but why would i swap it if i ill only switch from buffer[i]=buffer[x] ??
Printable View
but why would i swap it if i ill only switch from buffer[i]=buffer[x] ??
Because without a temporary variable, what you have currently happens. Watch:
Oops. Since you overwrote the C, you can't move it over to the W.Code:cow
[c] = [w]
wow
[w] = [w]
wow
Quzah.
yah thanks alot man i understand it now and i did it
Code:#include <stdio.h>
#include <string.h>
void reverse_it(char *buffer,int length)
{
int i,x;
char saver;
for(i=0,x=length-1;i<x;i++,x--){
saver=buffer[i];
buffer[i]=buffer[x];
buffer[x]=saver;
}
}
int main(void)
{
char name[]="NAME";
int i;
reverse_it(name,strlen(name));
puts(name);
getchar();
return 0;
}