Tuesday, 25 February 2014

Write a scanf function in c which accept sentence from user

Write a scanf function in c which accept sentence from user
#include<stdio.h>
#define MAX 500
int main(){
    char arr[MAX];
    printf("Enter any sentence which can include spaces.\n");
    printf("To exit press enter key.\n");
    scanf("%[^\n]s",arr);
    printf("You had entered: \n");
    printf("%s",arr);
    return 0;
}
Sample output:
Enter any sentence which can include spaces.
To exit press enter key.
this code make by ameerhamza my blog letsdoprogamminginc.bloagspot.com
You had entered:
this code make by ameerhamza my blog letsdoprogamminginc.bloagspot.com

No comments:

Post a Comment