is a string not null terminated ?


  • 0
    P

    I am getting a runtime error with this code . However if i use a strlen() function instead of '\0' termination i am getting a runtime error. any idea !?

    char* reverseWords(char* s) {

    int iter=0;
    int start=0;
    int end;
    char t;
    
    while(s[iter]!='\0')
    {
        while(s[iter]!=' '&&s[iter]!='\0') iter++;
        
        end=iter-1;
       
        while(start<end)
        {
            t = s[start];
            s[start] = s[end];
            s[end] = t;
            
            start++;
            end--;
        }
        iter++;
        start=iter;
    }
    
    return s;
    

    }


Log in to reply
 

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