In this example, we will emphasize on use of strings in c programming. We use strings to hold set of characters that can be sentence or word.
So here we will get a string through user input and then try to print that string character by character.
We are not printing string as whole rather character by character so that means we will store input in an array of characters and then based on indexed position the characters will be printed on screen.
First we will get the user input that can be word or sentence i.e. string and then hold that one into an array.
Once we are done with first step then we have to make use of loop so that we can iterate through array index by index and then capture each character at particular index position in an array.
For example, when we store a word in an array of size 5 then array can be referenced based on index position from 0 to 4 i.e. word will be stored in an array character by character starting from index position 0 to 4.
We will make use of for loop and iterate through loop
To print each character, we will use %c format specifier inside
Step by step approach:
First you must declare character array, say
Also declare counter variable i to use in
Use sizeof operator to find out
Inside for loop, Make use of %c format specifier to print each character through
printf("\n Enter a string: ");
Enter a string: c-programs