Hai,
I'm having problems with an assignment in C. Im supposed to write a program that takes a string and reverse it, and im not allowed to use standard functions for reversing the string.
Anyways, here's what i've come up with.
My problem is the actual swapping of letters inside the for loop
any ideas?
I'm having problems with an assignment in C. Im supposed to write a program that takes a string and reverse it, and im not allowed to use standard functions for reversing the string.
Anyways, here's what i've come up with.
PHP:
int strnlen(char *str){
char *p = str;
while(*p != '\0')
p++;
return p-str;
}
char *swapstring(char *strptr){
int len = strnlen(strptr);
char array[len];
char *str_start = strptr;
char *str_end = &strptr[len-1];
char *t = array;
char *m = array;
char temp;
while(*t++ = *str_start++ != '\0');
for(int i=0; i<len/2; i++){
m[i] = *(str_end--);
}
}
My problem is the actual swapping of letters inside the for loop
any ideas?