answersLogoWhite

0


Best Answer

cause getchar only read a character and scanf read only word before first space but not other words and letters.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

6y ago

The scanf() function is used to read formatted data from standard input. Whitespace is ignored thus it cannot be used to read a string containing spaces.

The getchar() function is used to read a single character from standard input and is functionally equivalent to getc(stdin). Although they can both be used to read strings from standard input, reading a string one character at a time is inefficient.

To read a string from standard input we can either use fgets() or (since 2010) getline().

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the limitations of getchar and scanf functions for strings?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Functions except gets and puts in c?

printf , scanf , getchar, putchar, getc are the other operators in C except gets and puts..


Scanf function in c for strings?

Use '%s', eg: char name[64]; scanf ("%s", name);


How do you read a character from the keyboard and will store it in the variable?

Use the scanf() function from the C standard library.


How Can We Solve The Limitation Of Getchar And Scan Function?

Getchar:-Reading a single character can be done by using the function getchar.Syntax:- variable_name = getchar ( );Variable_name is a valid 'c' name that has been declared as char type. When this statement is encountered, the computer waits until a key is pressed and then assigns this character as a value to getchar function. Since getchar is used on the right hand side of an assignment statement, the character value of getchar is in turn assigned to the variable_name on the left. The getchar function may be called successively to read the characters contained in a line of text. Getchar accepts space character.Scanf ("control strings",arg1, arg2, ………… argn);The control string specifies the field format in which the data is to be entered and the arguments arg 1, arg 2, arg n specify the address of locations where the data is stored. Scanf does not accept space character.


Example of formatted functions in C?

formatted functions::: Follows a fixed format like scanf,printf Unformatted functions:::Do not have fixed format like gets,getchar

Related questions

Functions except gets and puts in c?

printf , scanf , getchar, putchar, getc are the other operators in C except gets and puts..


Can you use getchar instead of scanf in a c program?

They do different things, read the manual/help for details.


Scanf function in c for strings?

Use '%s', eg: char name[64]; scanf ("%s", name);


How do you read a character from the keyboard and will store it in the variable?

Use the scanf() function from the C standard library.


How Can We Solve The Limitation Of Getchar And Scan Function?

Getchar:-Reading a single character can be done by using the function getchar.Syntax:- variable_name = getchar ( );Variable_name is a valid 'c' name that has been declared as char type. When this statement is encountered, the computer waits until a key is pressed and then assigns this character as a value to getchar function. Since getchar is used on the right hand side of an assignment statement, the character value of getchar is in turn assigned to the variable_name on the left. The getchar function may be called successively to read the characters contained in a line of text. Getchar accepts space character.Scanf ("control strings",arg1, arg2, ………… argn);The control string specifies the field format in which the data is to be entered and the arguments arg 1, arg 2, arg n specify the address of locations where the data is stored. Scanf does not accept space character.


Example of formatted functions in C?

formatted functions::: Follows a fixed format like scanf,printf Unformatted functions:::Do not have fixed format like gets,getchar


Is that any other way to input data in c language other than scanf function?

read, fread, gets, fgets, getc, fgetc, getchar, getch


What do you do when you receive the command 'Write C code to read input from user and save the input to a sequential file'?

Learn C! :-) There are several functions in C that can be used to read input from the user, such as getc(), getchar(), and scanf(). Files can be written to using fprintf() and putc(). They can be opened with fopen() and closed with fclose().


What is the use of getchar?

gets()Reads characters from stdin and stores them as a string into str until a newline character ('\n') or the End-of-File is reached.The ending newline character ('\n') is not included in the string.getchar()Returns the next character from the standard input (stdin).It is equivalent to getc with stdin as its argument. === ===


What are the commonly used input output functions in C?

Commonly used input/out functions in C are:* printf( )* scanf( )scanf() it is the standard input functions. It is used to get the data from the input devices, which is by default a keyboard, at run time, or execution time. Its general format is:scanf("one or more format specifier",& one or more variables separated by comma);For example:scanf("%d",&a);scanf("%d%,&a,&b);printf() It is the standard output functions it is used to show the data to an output device, which is by default a monitor screen, at run time, or execution time. Its general format is:In case of displaying the message:printf("Type the message here");for example:printf("Hello World");In case of printing the value:printf("one or more format specifier", & one or more variables separated by comma);for example:scanf("%d",&a);scanf("%d%f",&a,&b);


Printf and scanf Operators in C and C plus plus?

No, they are functions. Operators are -> or ++or /=


Difference between cin and scanf?

the getchar function waits the user hit a key followed by return key. Upon the return key hitted by the user the function returns the key. But the scanf can be used for various & different user entered data including text, integer, float and so on. in spite of getchar the delimeter keys for scanf function are tab, space and return key; so when a space entered by the user in the input the scanf will end the input and waits user enter the return key. You must take in mind that just the fragment of input that is behind these delimeters will be considered as legal input for the scanf and the remaninder will be escaped.