newline input: Runtime error in C code


  • 0
    D

    I do not understand whats the issue with this code? I get a runtime error for the test -
    Last executed input:
    "A man
    a plan
    a canal: Panama"

    '''
    char* reverseString(char* s) {
    char *result = malloc(sizeof(s) + 1);
    char *p = s + strlen(s) - 1;
    int i = 0;
    for(; i < strlen(s); i++){
    result[i] = *p--;
    }
    result[i] = '\0';
    return result;
    }
    '''


  • 0
    C
    • int lgt=strlen(s);
    • char result=(char)malloc(sizeof(char)*(lgt+1));

Log in to reply
 

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