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