Write a scanf function in c which accept sentence from user




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?





1. Write a c program to convert decimal number to hexadecimal number.
3. Write a c program to convert octal number to decimal number.
4. Write a c program to convert octal number to hexadecimal number.
5. Write a c program to convert hexadecimal number to decimal number.
6. Write a c program to convert hexadecimal number to octal number.
8. Write a c program to convert binary number to hexadecimal number.
9. Write a c program to convert binary number to octal number.
11. Write a c program to convert hexadecimal number to binary number.
12. Write a c program to convert octal number to binary number.
14. Write a c program to convert centigrade to fahrenheit.

5 comments:

Anonymous said...

thank you so much. lol

Banibrata Mandal said...

pleas explain it..
scanf("%[^\n]s",arr);

Vigneshrajan said...

/n denotes new line. once you pressed enter key the scanf statment ends

GloriaPoppyharlow said...

I hope there are still people here, but can I loop the array so that the program ask for multiple strings? and have it all displayed at the end? Thanks

Sivanandhana Girish said...

Had a great time reading your blog. Thanks for sharing this post to our vision.
Spoken English Classes in Chennai
Best Spoken English Classes in Chennai
IELTS Coaching in Chennai
IELTS Coaching Centre in Chennai
English Speaking Classes in Mumbai
English Speaking Course in Mumbai
IELTS Classes in Mumbai
IELTS Coaching in Mumbai
IELTS Coaching in Anna Nagar
Spoken English Class in Anna Nagar