16 Questions on C programming

User Generated

naqlgurjkzna

Programming

Description

1. What's cc? (Steps and what does each step do) 2. Given a C program, which is run as a.out this is a test int g; int h = 1; main(int argc, char *argv[]) | int A( int x, ......) { | { int a,b,c; | int u,v; a = 2; | b = 3; | HERE: c = A(a,b,"hello"); | } | } (1). Complete the function heading of A(....) (2). Which variables are global? which are local? (3). Which variables are in a.out? (4). Execution is at HERE: DRAW A DIAGRAM TO Show the stack contents from HERE to main()'s argc and argv. 3.Given: printu(unsigned int x), which prints an UNSIGNED integer. Write C code to print a SIGNED integer (which may be negative). 4. Assignment #2: YOUR printf(char *fmt, ...) is written as { char *cp; int *ip; .......... } which may be called as printf("abc %c xyz %s any %d thing %x\n", a,b,c,d); (1). Write C code to let cp point to the fmt string _____________ (2). Write C code to let ip point to the first parameter a _______________ (3). HOW do you print each of the items a,b,c,d?

Notes: List Processing and LAB #2

5. Write C statements for a struct containing name : an array of 32 chars key : an integer child : pointer to the first child node sibling : pointer to the next sibling node parent : pointer to the parent node A tree is implemented as a BINARY tree by the child and sibling pointers. Assume: struct node *p points at a node A. Write C code to print all children of A. struct node *q points at a new node. Write C code to add q as a child of A. Given: 0 1 2 3 4 5 6 7 int (*fptr[ ])(char *) = {menu, mkdir,rmdir,ls, cd, pwd, creat, rm}; Write C code to call the function create(char *pathname) Notes: Process Management in Unix LAB3 : Sh Simulator

6. Given: PATH=/bin:/usr/bin: .... :/usr/locl/bin:./ Write C code to tokenize PATH into separate dir strings 7. what does int pid = fork() do? after fork(); HOW TO TELL whether it's the parent or the child executing? What does int wait(int *status) do? What does int r = execve("pathname", argv, env); do? How does the system find pathname?__________________________________ Assume the Linux cat is in /bin directory. When running YOUR sh with cat file1 file2 file3 > outfile 8. Write C code to do output redirection > For the above commnad line cat file1 file2 fie3 > outfile: Draw a diagram to show exactly what's YOUR myargv in the r = execve("/bin/cat", myargv, env) call?_________________________ What's the value of r? ____________ 9. Write C code to do pipe in the command line cat filename | grep line 10. Relationship betwee open, close, read write fopen fclose fread fwrite 11. Given: struct stat myst. myst.st_mode, myst.st_atime Write C code to get information of a filename: Write C code to determine whether filename is a REGular file or a DIRectory. Write C code to test whether the file is Writeable by Others:____________________________ Readable by Others:____________________________ Write C code to print the file's access time in CALENDAR form. 12. Write C code to print the names of all entries in the current directory. 13. Fill in blanks for OPEN a file for read mode: _______ fd = open("file", _______); _______ fp = fopen("file", _______); char buf[4096]; (a). Write C code to read 4K bytes into buf[] using fd: ______________________ (b). Write C code to read 4K bytes into buf[] using fp: ______________________ Which of (a) and (b) is faster? WHY? _________________________________________ 14. Use system calls to display the contents of a file:______________________ use Library I/O functions to dispaly the contents of a file:_____________ 15. Given: cpf2f(char *f1, char *f2) copies REG file f1 to REG file f2. Write C code to copy a REG file /a/b/c into a DIRectory /x/y/z ___________

16. Write C code to test whether /a/b/c and /x/y/z are the SAME file:_________

User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Hey bro its done. Look a...


Anonymous
Great! 10/10 would recommend using Studypool to help you study.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags