Print the characters of String with space

Get a String and Prints it characters with Space

Sample Input 1:

Hello

Sample Output 1:

H e l l o

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#include<stdio.h> int main() { //write your code here }

Program or Solution

				
			
					
#include<stdio.h>
int main()
{
	char str[50];
	int i = 0;
	fgets(str,50,stdin);
	while(str[i]!='\0')
	{
		printf("%c ",str[i++]);
	}
	return 0;
}

	

			
				
			

Program Explanation

Get a String using fgets() function.

Str -> reads the string and stores it in str.

50 -> reads maximum of 50 characters stdin-> reads character from keyboard using for loop print all characters one by one.

"%c " in printf prints character with space.

Comments