C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 15th, 2013, 09:56 AM
avidwan avidwan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 avidwan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 14 sec
Reputation Power: 0
Reverse String Program In C

how can i reverse a string in c..? Please help me..

Reply With Quote
  #2  
Old January 15th, 2013, 10:02 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,835 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 15 h 19 m 43 sec
Reputation Power: 1774
You know, 6 posts in quick succession, each with NO EFFORT WHATSOEVER is a sure fire way of getting onto everyone's ignore list.

Given that your first post was "i have plan for develop a website for programming tutorials", it seems to me that you're just fishing for material.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old January 15th, 2013, 11:36 PM
zedeneye1 zedeneye1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 52 zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level)zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level)zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 14 h 36 m 53 sec
Reputation Power: 1
very easy..

most programming books usually include example programs of such kind...

And I'm not sure, but maybe one of the standard libraries already does contain such a function...(I don't know all the string functions by heart, try googling)

Reply With Quote
  #4  
Old January 15th, 2013, 11:37 PM
zedeneye1 zedeneye1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 52 zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level)zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level)zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 14 h 36 m 53 sec
Reputation Power: 1
Quote:
Originally Posted by salem
You know, 6 posts in quick succession, each with NO EFFORT WHATSOEVER is a sure fire way of getting onto everyone's ignore list.

Given that your first post was "i have plan for develop a website for programming tutorials", it seems to me that you're just fishing for material.


and somehow managing to fail even at that lol...

Reply With Quote
  #5  
Old January 16th, 2013, 06:26 AM
Sachin Bali Sachin Bali is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Sachin Bali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 42 m 30 sec
Reputation Power: 0
Quote:
Originally Posted by avidwan
how can i reverse a string in c..? Please help me..

#include <stdio.h>
void reverse_string(char[] arr);
void main()
{
char arr[30];
int i=0;
printf("Enter String of 6 character\t");
for(i=0;i<6;i++)
{
scanf("%c",&arr[i]);
}
print("Reverse of string is\n");
reverse_string(arr);
getch();
}
void reverse_string(char[] arr)
{
char arr2[30];
int i=0, j=0;
for(i=0,j=5;i<6;j--,i++)
{
arr2[i] = arr[j];
}
for(i=0;i<6;i++)
{
printf("%c",arr2[i]);
}
}

Reply With Quote
  #6  
Old January 16th, 2013, 06:32 AM
swapy swapy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Posts: 66 swapy Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 14 h 4 m
Reputation Power: 0
You can simple use string reverse function strrev
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str1[10]="Hello";

strrev(str1);

puts(str1);

getch();
return 0;
}

Reply With Quote
  #7  
Old January 17th, 2013, 05:37 PM
BobS0327 BobS0327 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 118 BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level)BobS0327 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 18 h 48 m 29 sec
Reputation Power: 44
Well, I offer the following as an example for your programming website

Code:
#include <stdio.h>
#include <string.h>

char* reverse_string(char* str)
{
	for(int beg = 0,  end = strlen(str) - 1; beg < end; ++beg, --end)
	{
		str[beg] ^= str[end];
		str[end] ^= str[beg];
		str[beg] ^= str[end];
	}
	return str;
}

int main(void)
{
	char buffer[]="Hello World";
	printf("%s\n", reverse_string(buffer));
	return 0;
}
Comments on this post
codergeek42 agrees: A clever use of XOR-swap algorithm.

Reply With Quote
  #8  
Old January 17th, 2013, 07:53 PM
zedeneye1 zedeneye1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 52 zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level)zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level)zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 14 h 36 m 53 sec
Reputation Power: 1
Quote:
Originally Posted by Sachin Bali
#include <stdio.h>
void reverse_string(char[] arr);
void main()
{
char arr[30];
int i=0;
printf("Enter String of 6 character\t");
for(i=0;i<6;i++)
{
scan("%c",&arr[i]);
}
print("Reverse of string is\n");
reverse_string(arr);
getch();
}
void reverse_string(char arr)
{
char arr2[30];
int i=0, j=0;
for(i=0,j=5;i<6;j--,i++)
{
arr2[i] = arr[j];
}
for(i=0;i<6;i++)
{
print("%c",arr2[i]);
}
}


are you making some mistakes or is that some other version of C where "scan" works instead of "scanf"...?

Reply With Quote
  #9  
Old January 17th, 2013, 11:22 PM
Sachin Bali Sachin Bali is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Sachin Bali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 42 m 30 sec
Reputation Power: 0
Quote:
Originally Posted by zedeneye1
are you making some mistakes or is that some other version of C where "scan" works instead of "scanf"...?


By mistake. It should be "scanf" instead of "scan".

Reply With Quote
  #10  
Old January 17th, 2013, 11:34 PM
zedeneye1 zedeneye1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 52 zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level)zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level)zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 14 h 36 m 53 sec
Reputation Power: 1
Quote:
Originally Posted by Sachin Bali
By mistake. It should be "scanf" instead of "scan".


and printf and several many other errors...

Reply With Quote
  #11  
Old January 17th, 2013, 11:37 PM
Sachin Bali Sachin Bali is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Sachin Bali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 42 m 30 sec
Reputation Power: 0
Quote:
Originally Posted by zedeneye1
and printf and several many other errors...


I already updated the code. Please check that first.

Reply With Quote
  #12  
Old January 18th, 2013, 03:23 AM
zedeneye1 zedeneye1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 52 zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level)zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level)zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 14 h 36 m 53 sec
Reputation Power: 1
Quote:
Originally Posted by Sachin Bali
I already updated the code. Please check that first.


copy/paste the code in a compiler, there are still errors. I know cuz I checked. copy/pasted it in codeblocks and there's 5-6 errors, although the concept is clear. I can see what you did there...

Reply With Quote
  #13  
Old January 18th, 2013, 03:32 AM
Sachin Bali Sachin Bali is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Sachin Bali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 42 m 30 sec
Reputation Power: 0
Quote:
Originally Posted by zedeneye1
copy/paste the code in a compiler, there are still errors. I know cuz I checked. copy/pasted it in codeblocks and there's 5-6 errors, although the concept is clear. I can see what you did there...


Don't copy paste and execute the code. My work was to write algorithm and to clear the concept. Its the user responsibility to use it and to take care of the syntactical mistakes.


Don't take it as confirm code. Take it as a algorithm.

Reply With Quote
  #14  
Old January 18th, 2013, 03:42 AM
zedeneye1 zedeneye1 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 52 zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level)zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level)zedeneye1 User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 14 h 36 m 53 sec
Reputation Power: 1
Quote:
Originally Posted by Sachin Bali
Don't copy paste and execute the code. My work was to write algorithm and to clear the concept. Its the user responsibility to use it and to take care of the syntactical mistakes.


Don't take it as confirm code. Take it as a algorithm.



Reply With Quote
  #15  
Old January 18th, 2013, 11:50 AM
avidwan avidwan is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 avidwan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 14 sec
Reputation Power: 0
reverse string in c

Thank You Very Much..

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Reverse String Program In C

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap