Somone please help me writing a code for "Reverse a word in a String" in c..
Ex: My name is XYZ
o/p:XYZ is name My
deepak.hm123
0
Newbie Poster
Recommended Answers
Jump to Post//Declare an str char str[50],str1[50]; accept gets(str); for(init to end of str;>0;var--) store str1[1] = str[n] print str1;
Jump to PostHere's my code
void main() { char str[60],str1[60]; int i = 0,j=0,k=0,end =0; clrscr(); gets(str); while(i<strlen(str)) { if(str[i] == ' ' || !str[i+1]) { str1[k] = ' '; k++; if(!str[i+1]) i++; for(j = i-1;j>=end;j--) { str1[k]= str[j]; k++; } end = i; } i++; } k--; for(;k>0;k--,printf("%c",str1[k])); …
Jump to PostIf you need an explanation on the concepts of string reversing, I have a very detailed explanation in this post:
All 11 Replies
Rahul.menon
0
Light Poster
deepak.hm123
0
Newbie Poster
Rahul.menon
0
Light Poster
N1GHTS
102
Posting Whiz in Training
Rahul.menon
0
Light Poster
N1GHTS
102
Posting Whiz in Training
deepak.hm123
0
Newbie Poster
vijaykrishnabor
-7
Newbie Poster
WaltP
commented:
We do NOT give code to prople. That's cheating.
-3
Rahul.menon
0
Light Poster
Rahul.menon
0
Light Poster
N1GHTS
102
Posting Whiz in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.