Write a function that takes a string as input and returns the string reversed.

Example:
Given s = "hello", return "olleh".


char* reverseString(char* s) {
    char *str;
    str = s;
    int i=0;
    char tmp='d';
    while(*str){
        i++;
        str++;
    }
    str = s;
    for(int p=0;p<i/2;p++){
        /*
         tmp=*str+p;
         *(str+p) = *(str+i-p-1);
         *(str+i-p-1)=tmp;
        */
        tmp=str[p];
        str[p]=str[i-p-1];
        str[i-p-1]=tmp;
    }
    return str;
}

results matching ""

    No results matching ""