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);
}
5. What does the standard I/O library function int getchar() do? Why does it return an...
What does this function do? int mystery(double employees[], double id, int size) { for (int i = 0; i < size; i++) { if (id == employees[i]) { return i; } } return -1; } A. This is a function that performs a search. If the id is found in the employees array, its index location is returned, otherwise -1 is returned. B. This is a function that sorts the employees array C. This is a function that returns all...
5.43 (10 pts) What does the following program do? #include <stdio.h> 3 unsigned int mystery Cuns igned int a, unsigned int b): // function prototype 5 int main(void) printf("%s". "Enter two positive integers: unsigned int x: I/ first integer unsigned int y: // second integer scanf("Su%u". &x, &y); "); 12 13 14 15 II Parameter b must be a positive integer 16 to prevent infinite recursion 7 unsigned int mystery Cuns igned int a, unsigned int b) 18 printf("The result...
Question 5: A) Consider: int i=1; int fun(int x) { for(int i=0; i<4; i++) { x += i; return x; What value is returned by a function call fun(1)? B In C, static variables can only be initialized by literals, not functions. For example, this is allowed: static int x = 5; But this is not allowed: static int x = compute_initial(); Why would this be the case? A Because you can never initialize a variable using a function, even...
1. When using a function in the Python standard library, do you need to import the library into your program before using the function? 2. How does the walk of a pseudorandom sequence differ from the walk of a truly random sequence? 3. Is the computer capable of producing a truly random walk in a reasonable amount of time? 4. Based on your research in the standard library documentation, what is the name of the function that can be used to generate random integer...
Having an issue with pointers and functions. #include <stdio.h> int f(int *a, int *b); int main() { int a = 2, b = 7; b = f(&b, &a); printf("a = %d,\n", a); printf("b = %d\n", b); return 0; } int f(int* a, int* b) { (*a) = (*a) + 3; (*b) = 2*(*a) - (*b)+5; printf("a = %d b = %d\n", *a, *b); return(*a)+(*b); } can someone explain to me why the output is a =...
c program that counts the number of characters, words and lines from standard input until EOF. attached is what i Have so far but its not working ?. about shell redirection Requirements 1. Write a C program that counts the number of characters, words and lines read from standard Input until EOF Is reached. 2. Assume the Input is ASCII text of any length. 3. Every byte read from stdin counts as a character except EOF 4. Words are defined...
Why does a task statement not require inputs, but function statement, module template and system task do? What is the difference between task and system task?\ Can high fanouts cause a time constraint?
How do I set up my read function? here's my code so far: int read_sudoku_board(const char file_name[], int board[9][9]) { FILE * fp = fopen("sudoku.txt", "r"); int a,i,j,c; int count = 0; for(i = 0; i < a; i++){ for(j = 0;j < 9;j++){ c = fgetc(fp); if(c == '-'){ board[i][j] = 0; } else if(c >= 1 && c <= 9) printf(" %d"); else return -2; } count++; } if(count != a-1) return -1; else return 0; }12 Read...
How to prove G(n)=n+1 in this algorithm? 1. if (n 0) 2. return 1 3. else if (n1) f 4. return 2 5. else if (n 2) 6. return 3 7. else if (n3) t 8. return 4 else f 9. int OGnew int[n 11 10. G[O]1 12. G[2]3 13. G[3]4 14. int i:-4 15. while (i<n) t 16. if (i mod 20) else ( 20. return G[n] 1. if (n 0) 2. return 1 3. else if (n1) f...
C++ programming 6-1: User Defined Functions I the C++ cmath library contains several math-related functions. for a general listing of functions contained within this library, review your text or visit Cplusplus.com (http://www.cplusplus.com/reference/cilbrary/cmath/) if you had the option to redesign the math library, what other functions would you add to it? for example, do you think a max function or average function might be useful? give a list of at least three functions you think are worth adding to the math...