reverse.c |
#include <stdio.h> void reverse(char s[]); /* this program is not highly successful must remember to terminate string with '\0' */ main(){ char string[8]; string[0]='f'; string[1]='p'; string[2]='@'; string[3]='s'; string[4]='t'; string[5]='i'; string[6]='o'; string[7]='\0'; printf("%s\n", string); reverse(string); printf("%s\n", string); return 0; } void reverse(char s[]){ int i = 0; int temp = 0; int z = 0; while(s[i]!='\0') ++i; for(z=0; z<(i/2); ++z){ temp = s[z]; s[z] = s[i-(z+1)]; s[i-(z+1)] = temp; } return; } |
James Little |