Function to reverse string in C

后端 未结 4 1159
终归单人心
终归单人心 2021-01-28 08:03

I wrote this function to reverse a string in C, but when switching characters in the string the program crashes. I have no idea what\'s causing it, so any help would be apprecia

4条回答
  •  执念已碎
    2021-01-28 08:54

    This should work:

    #include
    
    int main()
    {
      char str[100], temp = 0;
      int i = 0, j = 0;
    
      printf("nEnter the string :");
      gets(str);
    
      i = 0;
      j = strlen(str)-1;
    
      while(i

提交回复
热议问题