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.

3 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