Skip to content

In this program we reverse a string that is stored in a character array by using a for loop.

Notifications You must be signed in to change notification settings

pooja210603/Reversing-a-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Reversing a string

Strings

Strings are used for storing text/characters. For example, "Hello World" is a string of characters. Unlike many other programming languages, C does not have a String type to easily create string variables. Instead, you must use the char type and create an array of characters to make a string in C:

char test[] = "Hello World!";

Access Strings

Since strings are actually arrays in C, you can access a string by referring to its index number inside square brackets [].

printf("%c", test[0]);

Algorithm:

  1. Ask user to input a string to be reversed.
  2. Store it in an array.
  3. Calculate the length of the string by using the strlen function.
  4. Apply a for loop from (counter variable= length-1) initially and decrementing the value till (counter variable>=0) , printing the array in reverse.

image

Output of the program:

image

About

In this program we reverse a string that is stored in a character array by using a for loop.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages