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.

7 comments:

Anonymous said...

thank you so much. lol

Unknown said...

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

Unknown 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

Anonymous said...

Just copied the WHOLE code, it made an exception: Exception thrown at 0x00007FFCEFC0F3A9 (ucrtbased.dll) in Project6.exe: 0xC0000005: Access violation writing location 0x0000006B2C7A0000.

Anjali said...

Interview Tips | Interview Question and Answers by Searchyours | Free Article Submission Site

Indpac said...

Very useful blog thanks for sharing IndPac India the German technology Packaging and sealing machines in India is the leading manufacturer and exporter of Packing Machines in India.