Search C Program | nimishsoft@gmail.com

String Reverse - STRREV

/* STRING REVERSE - STRREV */

#include<stdio.h>

int main()
{
 char str[100];
 int i,j;
 char c;
 printf("Please enter a string: ");
 // gets(str); 
 // fgets is a better option over gets to read multiword string .
 fgets(str, 100, stdin);
 // Following can be added for extra precaution for '\n' character
 // if(str[length(str)-1] == '\n') str[strlen(str)-1]=NULL;
   
 for(i=0;str[i];i++);
 for(j=0,i--;j<i;j++,i--)
 {
  c=str[i];
  str[i]=str[j];
  str[j]=c;
 }

 printf("Reversed string is: %s",str);

 return 0;
}

7 comments:

  1. for what is the 100 in the>>> char str[100];

    ReplyDelete
    Replies
    1. array size, the number or chars it can store

      Delete
    2. is ter any simple program for this

      Delete
    3. mnbk jjk kjlj k lkljl
      hoping it may work

      Delete

  2. Codeworld19

    codeworld19 C and c++, codeworld19 Java, codeworld19 Python, codeworld19 Database sql,mongoDB, Hadoop, codeworld19 All hacker rank problem solutions

    ReplyDelete