Jul 31, 2020

C program to separate the individual characters from a string

Ex: Write a C program to separate the individual characters from a string. How to write a C program to separate the individual characters from a string. C program to separate the individual characters from a string.

Input from user:


Enter the string:

codeforhunger.com

Expected output:


String characters are:

c o d e f o r h u n g e r . c o m





  Step by step logic of the given program:


1. Accept string from user declare variable say str.

2. Run while loop till end of string.

3. Print characters of string one by one using spaces.




  Program to separate the individual characters from a string :


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

int main()
{
char str[100];//declare string of size 100
int i=0;
printf("Enter the string:\n");
gets(str);//accept string
printf("String characters are:\n");
while(str[i]!='\0')
{
printf("%c ",str[i]);
i++;
}
return 0;
}


Above program shows the following output:

C program to separate the individual characters from a string


To learn more string exercises click here...


No comments:

Post a Comment

If you have any doubts, please discuss here...