C Program to Read Input and Print String

Write a C program to read input and print string as an output. For example, we can use the gets method to read the user input and %s formatted to print the string as an output.

#include <stdio.h>

int main()
{
    char msg[100];
    
    printf("Please enter Any String or Message = ");
    gets(msg);

    printf("The string that you entered = %s\n", msg);
    
    return 0;
}
C Program to Read Input and Print String

This C program uses the fgets function to read the user input and prints that string as an output.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char msg[100];
    
    printf("Please enter Any String or Message = ");
    fgets(msg, sizeof msg, stdin);

    printf("The string that you entered = %s\n", msg);
    
    return 0;
}
Please enter Any String or Message = hello c programmers
The string that you entered = hello c programmers

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.