C Program to accept the string with spaces

C Program to accept the string with spaces 


#include<stdio.h>
int main()
{
    char a[101];
    printf("enter a string : ");
    scanf("%[^\n]",&a);
    printf("%s",a);
    return 0;
}

Output:

              


E
xplanantion:

       Hi, in this program using this "%[^\n]" the string is accepted

until the next line is entered and we are printing the  string

using printf function.

Previous Post Next Post