20_10

Write a C code to reverse a string without using any string library functions.

 Source code:

/*Write a C code to reverse a string without using any string library functions , e.g. '12345' should be '54321'. */

#include <stdio.h>

#include <string.h>

int main(){

    char str[20];

printf("Enter a string:");

    //Read String

    scanf("%s", str);

int temp;

int i=0,j=0,length;


while (str[j] != '\0')

        j++;

        j--;

    while (i<j) {

        temp=str[i];

        str[i]=str[j];

        str[j]=temp;

        i++;

        j--;

}

printf("The reverse string:%s",str);

return 0;

}

Output:

C code to reverse a string without using any string library functions


No comments:

Post a Comment

Write a program in C to convert a decimal number to binary using recursion.

 Source code: //Write a program in C to convert a decimal number to binary using recursion. #include<stdio.h> long convertB_to_D(int d...