A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to reverse a string without using library function
Q:

C program to reverse a string without using library function

0

C program to reverse a string without using library function

In this program, we will learn how to reverse a string without using library function?

Here, we are declaring two strings (character arrays), first string will store the input string and other will store the reversed string.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
#include <string.h>
 
int main()
{
    char str[100],revStr[100];
    int i,j;
 
    printf("Enter a string: ");
	scanf("%[^\n]s",str);//read string with spaces

 
    /*copy characters from last index of str and
 store it from starting in revStr*/
    j=0;
    for(i=(strlen(str)-1); i>=0;i--)
        revStr[j++]=str[i];
     
    //assign NULL in the revStr
    revStr[j]='\0';
 
    printf("\nOriginal String is: %s",str);
    printf("\nReversed String is: %s",revStr);
 
    return 0;
}

Output

Enter a string: This is a test string
Original String is: This is a test string
Reversed String is: gnirts tset a si sihT

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now