Question

5. What does the standard I/O library function int getchar() do? Why does it return an int? 6. What is the difference between
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Question 1st Answer

What does the function int getchar()

The c library function int getchar() get a character that means the unsigned char from the stdin this can contain eqivalent to get with stdin as its argument.that it reads reads a single character from standard input stream stdin,regardless of what it is and returns to the program.it can specified in ANSI-C and it contain the basic function in c.

For example

#include<studio.h>

Int main()

Char d;

Printf("welcome");

d=getchar();

Printf("to the panel");

Putchar(d);

Return(0);

}

The output will

Welcome:a

To panel:a

Why it return an int

The getchar() function returns am interger value which is reprsentation of the charchet entered the reason it return an int rather than char is because it need tobe able to store any character plus EOF indicator where the input stream is closed

Question 2

Difference between scanf(),fscanf(),sscanf()

Scant contain

Scanf(format[,pointer]...)

Char*format;

fscanf contain

Fscanf(dtream,format[,pointer]...

FILE * stram;

Char * format;

The sscanf contain

sscanf(s,format[,pointer]...)

Char *s, *format;

The scant reads from the standard input stream that stdin.fscan reads from the input dtream stram and the sscanf reads from the charchet string s.each function reads character,interpreter them according to format and store the result in its argument.each except,as argument,a control string format declined  below and a set of pointer arguments indicating where the converted input should be stored.the control string usually contains conversion specification which are used to direct interpretation of input sequences the control string many contain the blanks,tabs.or a new line which causes input to be read up to the next non white space character

An ordinary character that not% which must match the next chapter of the input stream

Conversion specification consisting of character % ,an optional assignment suppressing character *,an optional numeric maximum field width,an a conversion character

Third question

Scanf()

#include<studio.h>

int scanf(const char *format-string,argument-list);

The scanf() function return the number of field that were successfully converted and assigned the return value does not include field the were read but not assigned the return value EOF for an attempt to read end of file if no conversion was performed.it pretty clear that scan return an interger value the int value corresponding to the number of character successfully read as defined by using%for format and & for address variable it stops when the format sting in executed after successfully reading all.

fsacnf()

#include<studio.h>

int fscanf (File *stream,const char *format-string,argument-list)

The fscanf() function return the number of field that it successfully converted and assigned the return value does not include field that the scanf() function read but did not assign.the return value is EOF of an input failure occurs before conversion or number of input item assigned if successful.the fsacnf() reads the data from current position of specified stream into the location that given by the entries in argument-list,if any each entry in argument list must be a pointer to a variable with a type of corresponding to type specified in format string.

Sscanf()

#include <studio.h>

Int sscanf(const char *buffer, const char *format, argument-list);

The sscanf() function return the number of field that were successfully converted and assigned.the return value does not include field that were read but not assigned the return value of EOF when the end of the string is encountered before anything is converted.the sscanf() function reads from buffer into the location that are given by argument-list.each argumne must be a pointer to a variable with a type that correspond to a type specifie in format-string

Question fourth

The c library function int system(const char *command) passes the command name or program name specified by command to the hot environment to be executed by the command processor and returns after the command has been completed.the system functioning allow a c program to run another program by passing command line that means the pointed to by string to the operating systems command processor that will then be executed.the system function return a nonzero value ig command processer is available and string is a bull pointer.the system function returns an implication defined value string isn't a bull pointer

Example

#include<iostram.h>

#include<studio.h>

#include<stdlib.h>

#include<string.h>

int main()

Char command[40];

strcpy( command, ls-l)

system(command);

return(0);

}

Add a comment
Know the answer?
Add Answer to:
5. What does the standard I/O library function int getchar() do? Why does it return an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT