C Program to print each letter one after the other for the given string | codeitwise

Here we are going to write a program to print each letter one after the other for the given string in c. We will take a string input from the user and print each letter of that string one by one. 

We will use for loop to iterate through the string and print each character.

There are several ways of declaring a string in c.


char c[]="codeitwise";
char c[10]="codeitwise";
char c[10]={'c','o','d','e','i','t','w','i','s','e'};
char c[]={'c','o','d','e','i','t','w','i','s','e'};
char c[10];
c="codeitwise";


we will take a string input from the user. Then we will find the length of that string by using strlen() function which is present in string.h header file so we need to include string.h header file in our program.

Now lets write program to print each letter one after the other for the given string in c.


C Program to print each letter one after the other for the given string-


#include <stdio.h>
#include <string.h>

int main()
{
    char st[10];
    printf("Enter your string: ");
    scanf("%s",st);
    
    for(int i=0;i<strlen(st);i++)
    {
        printf("%c\n",st[i]);
    }
    return 0;
}

Output-

Enter your string: codeitwise
c
o
d
e
i
t
w
i
s
e


Post a Comment

If you have any doubts, please let me know

Previous Post Next Post