C program to accept string from user & print it on the output screen

Ex: Write a C program to accept string from user and print it on the output screen. How to accept string from user and print it on the output screen. C program to accept string from user and print it on the output screen.

Input from user:

Enter the string:
I love codeforhunger

Expected output:

You entered:
I love codeforhunger






  Step by step logic of the given program:

1. Declare string of size 100, declare variable say str.

2. Accept string using gets() function and store it in variable str.

3. Print string on the output screen.




  Program to accept string from user and print it on the output screen:


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

void main()
{
char str[100];

printf("Enter the string:\n");
 gets(str);

printf("you entered: %s",str);
}



Above program shows the following output:


C program to accept string from user and print it on the output screen

No comments:

Post a Comment

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