C program string funtion

C program to reverse a string without using string function(strrev)  : 



Hello readers, in this post i am going to write a C program which has been asked in Interview from long time.
The question is  “Write a program to reverse a string without using strrev() in C”.
Well, I going to write a very simple C program to reverse a string for the above question.

WE know  for loop  




Required  knowledge : 

➤  string , for loop , recursion 





C Program to reverse a string:
Output of the above program will be:
It’s a pretty easy program, so just read the comments in the above C program to understand what each line of the code is doing.


Enjoy the day!

 or 
 progaram : 


#include<stdio.h>
#include<string.h>
int main()
{
    char str[100]="atikur rahman";
    char str3[100];
    int i,len,j;
    len=0;
    for(j=0;str[j]!='\0';j++){
        len++;
    }
    for(i=len-1;i>=0;i--){
         printf("%c",str[i]);
    }


    return 0;
}



  OR
 progaram : 


#include<stdio.h>
#include<string.h>
int main()
{
    char str[100]="atikur rahman";
    char str3[100];
    int i,len,j;
    len=0;
    for(i=0;str[i]!='\0';i++){
        len++;
    }
    for(j=0,i=len-1;i>=0;i--,j++){
        str3[j]=str[i];
    }
    str3[j]='\0';
    printf("%s",str3);
    return 0;
}


OUTPUT:




No comments

Powered by Blogger.