A C code to reverse a string -


does see bug here? have got alternate solutions.

int main() {    char line[100], res[100], temp[20];   fgets( line, 100*sizeof(char), stdin);       int i, j, l;   for( i=strlen(line)-1; i>=0; i--)   {     if(line[i]==' ')         for(j=i+1, l=0; line[j]!=' ' && line[j]!='\0'; l++, j++)             temp[l]=line[j];     temp[++l]=' ';     temp[++l]='\0';     strcat(res, temp);   }   puts(res);   return 0; } 

l , j initialized when line[i]==' '.

witch won't case first iteration, line[i] '\n'


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -