CS1050 – C Programming Quiz 9 FALL 2015 Fill out the answer sheet with your choi
ID: 3719031 • Letter: C
Question
CS1050 – C Programming Quiz 9
FALL 2015
Fill out the answer sheet with your choices and turn the quiz in. DO NOT PUT YOUR ANSWERS ON THIS
SHEET – RECORD THEM ON THE ANSWER SHEET ONLY.
Use the code below to answer the next questions in this partial program
a) #include
b) int main (int argc, char *argv[] ) {
c)
FILE *inFilePtr, *outFilePtr;
d)
int c;
e)
if (argc != 4) {
f)
printf("Usage: mycopy infile outfile ");
g)
}
h)
else {
i)
if ( ( inFilePtr = fopen( argv[ 1 ], "r" ) ) != NULL ) {
j)
if ( ( outFilePtr = fopen( argv[ 2 ], "w" ) ) != NULL {
IF the user started this program with this command line: “./a.out sue.dat fred.txt infile.x” what would
1) the value of argc be?
2) the value of argv [ 1 ] be?
3) Which line of code creates a double pointer?
4) What does the “r” on line j mean?
5) What does the “w” on line i mean?
6) Provide the name of one file pointer being used in this program.
7) The following statement
printf( “%s ”, ‘c’ );
should print the character
’c’
but has an error because
a) printf cannot be used with characters
b) conversion specifier
s
expects an argument of type pointer to char
c) the
should be outside the quotes
d) there is
NO
error in this statement
8) The following statement
printf( “%.3f%”, 9.375 );
should print
9.375%
but has an error because
a) the
.3
should be
.4
to get the precision needed
b) you must use conversion specifier %% to get the % sign to print out
c) you can’t have two % signs in one statement
d) there is
NO
error in this statement
9) The following statement
printf(“%s ”, ‘Richard’ );
should print out
Richard
but has an error
because
a) there should be a “%c” instead of a “%s”
b) Richard must be in double quotes
c) there is
NO
error in this statement
10)The following statement
printf(“”A string in quotes””);
should print out
A string in quotes
but has
an error because
a) there is no identifier
b) you can’t print a string out without a %s
c) the ** characters must be removed
d) there is
NO
error in this statement
if it is not clear look at the pictures here ( they are the same)
Thanks!
CS1050 - C Programming Quiz 9 FALL 2015 Fill out the answer sheet with your choices and turn the quiz in. DO NOT PUT YOUR ANSWERS ON THIS SHEET - RECORD THEM ON THE ANSWER SHEET ONLY. Use the code below to answer the next questions in this partial program a) #include b) int main (int argc, char *argv|){ c) d) e) FILE *inFilePtr, *outFilePtr; int c; if (argc! 4) printf("Usage: mycopy infile outfile n"); g) h) else ifCÓ inFilePtr = fopen( argv[ 1 ], "r" ) != NULL ) { if ( ( outFilePtr- fopen( argv[ 2 ], "w"))!NULL{ IF the user started this program with this command line: "./a.out sue.dat fred.txt infile.x" what would 1) the value of argc be? 2) the value of argv [1] be? 3) Which line of code creates a double pointer? 4) What does the “r" on line j mean? 5) What does the "w" on line i mean? 6) Provide the name of one file pointer being used in this program 7) The following statement printf("%s ",'c' ); should print the character 'c, but has an error because a) printf cannot be used with characters b) conversion specifier s expects an argument of type pointer to char c) the should be outside the quotes d) there is NO error in this statement 8) The following statement printf "%.31%", 9.375); should print 9.375% but has an error because a) the .3 should be .4 to get the precision needed b) you must use conversion specifier %% to get the % sign to print out c) you can't have two % signs in one statement dn there is NO error in this statementExplanation / Answer
1.The value of argc will be the the count of command line arguments.Here it is 4
2. The value of argv[1] is sue.dat
3.Hope We don't have any double pointers in this program
4. r means: open the file for read only. If the file is opened successfully data will be loaded into memory and sets up a pointer to the first character.
5. w means: open the file to write into it. If the file exists, then the contents in that file are overwritten. If there is no such file, it will create a new file.
6. File Pointer : inFilePtr
7. Ans : B
8. Ans : B (you must use %% to get %)
9. Ans : B (Richard must be in double quotes)
10.Ans : D (Threre is no error in this statement it perfectly prints the "Richard" with quotes)