[C] Runtime Error


  • 0
    W
    char* reverseString(char* s) 
    {
    int stringLen = strlen(s);
    char destiStr[100];
    int i = 0, j = 0;
    
    for (i = stringLen - 1, j = 0; i >= 0; i--, j++)
    	destiStr[j] = *(s + i);
    destiStr[j] = '\0';
    printf("destiStr = %s\n", s);
    
    return destiStr;
    }

  • 0
    W

    Your "destiStr" has a changeless lenth, once input out of your range,it might be wrong, try reverse the str right on input str.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.