Write a scanf function in c which accept paragraph or sentence from user | CTechnotips


Write a scanf function in c programming language which accept paragraph from users

#include<stdio.h>
#define MAX 500
int main(){
    char arr[MAX];
    printf("Enter any paragraph which can include spaces or new line.\n");
    printf("To exit press the tab key.\n");
    scanf("%[^\t]s",arr);
    printf("You had entered: \n");
    printf("%s",arr);
    return 0;
}

Sample output:

Enter any paragraph which can include spaces or new line.
To exit, press the tab key.
C is powerful language.
I am learning c from
ctechnotips.blogspot.com
You had entered:
C is powerful language.
I am learning c from
ctechnotips.blogspot.com


Write a scanf function in c programming language 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.
May I help you?
You had entered:
May I help you?

0 comments:

Post a Comment