Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to reverse a string in C ?

Status
Not open for further replies.

sacrpio

Member level 3
Member level 3
Joined
May 24, 2004
Messages
56
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
500
reverse of string.

I want to reverse this string in C, suggest please.

string: "hello what is your name"

I want reverse of this string in this for.

reverse string: "name your is what hello"
 

Re: reverse of string.

this is my quick and dirty solution

char Buffer1[100] = "hello what is your name";
char Temp[100] = "";
char Buffer2[100] = "";
char *pBuffer = &Buffer1[0x00];

strcat(Buffer1," ");
while(strstr(pBuffer," ") != 0x00)
{
strncpy(Temp,pBuffer,strstr(pBuffer," ")-pBuffer);
Temp[strstr(pBuffer," ")-pBuffer] = '\0';
pBuffer = strstr(pBuffer," ") + 0x01;

strcat(Temp," ");
strcat(Temp,Buffer2);
strcpy(Buffer2,Temp);
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top