Computing Quiz 5

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/66

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

67 Terms

1
New cards

The function used to open a file and return a FILE pointer for that file is

fopen()

2
New cards

When a file fails to open, fopen returns or evaluates as

NULL

3
New cards

The format specifier to display floating point numbers in scientific notation is the percent sign followed by the letter: 

%e

4
New cards

The format specifier used to change the number of decimal places displayed in a floating point numbers is the percent sign followed by the letter: 

%.nf

5
New cards

“/n” is a _____ and ‘/n’ is a _____

Escape sequence, character

6
New cards

Write the format specifier used to change the number of decimal placed displayed in a floating point number to 3 decimal places

%.3f

7
New cards

Which functions read one character even if that character is a blank space

getchar()

8
New cards

The format specifier to display floating point numbers in the shortest notation is the percent sign followed by the letter: 

%g

9
New cards

When you are finished using a file you should close the file using the function

fclose()

10
New cards

_______ is the safe function used to get a restricted length c-string from a file or the keyboard

fgets()

11
New cards

The special character used to mark the end of a C-string is called the ____ character

null

12
New cards

All data is input and output as ______ data

character

13
New cards

scanf, fscanf and sscanf return

Number of successfully assigned inputs (EOF)

14
New cards
  • + is a format specifier flag that 

Displays a + infront of positive numbers

15
New cards

Which of the following is not used when using files for input and output?

Prompting the file to ask for data

16
New cards

Which of the following function declarations will correctly pass a FILE pointer to the function?

void display (FILE* out)

17
New cards

In order to read data from a file correctly you

Must know the kind of data in the file

18
New cards

When is the external name of the file used in the program?

When opening the file

19
New cards

Which function returns true if the character argument is a digit? 

isdigit

20
New cards

If the user types in the characters ‘1’ and ‘0’ and your program reads them into an integer variable with no spaces in between using scanf and %d, what is the value stored into that integer? 

10

21
New cards

The function fgetc function reads

One character value

22
New cards

If a file did not open correctly, you should

Display an error message and take some suitable action such as exit

23
New cards

Which of the following is the correct way to determine if a file referred to in the FILE pointer named inFile failed to open correctly after calling fopen? 

if (inFIle==NULL)

24
New cards

The command fprintf(outFile, “%*d”, width, x); is used to

Display the integer x in at least width characters

25
New cards

The fputc function outputs

One character value

26
New cards

To open a file with a user supplied name, you would need to store the name in a variable. If the file name was to have no more than 20 characters in it, which would be an appropriate declaration of the file name variable? 

char filename[21]

27
New cards

To open an output file and add to the end of the data already in the file using the FILE pointer fp you would write ______

fp=fopen(“project.txt”, “a”);

28
New cards

If the name of the input file was in a c-string variable named filename, which of the following is the correct way to open the file for reading and associate it with the FILE object referred to by the FILE pointer named inFile?

inFile=fopen(filename, “r”)

29
New cards

We have a file that has a name in it, but the name is written one character per line. We need to write this name to the screen without the newlines. What is wrong with the following code?

Our output has new lines in it.

30
New cards

Which include directive is necessary for file IO?

#include <stdio.h>

31
New cards

A ______ is a variable that has unknown structure and is only modified through a pointer variable called a handle through function calls 

Opaque object

32
New cards

Which statement correctly opens a file named project.txt for reading and holds the address of the FILE object in a variable named in_file

in_file=fopen(“project.txt”, “r”);

33
New cards

What is wrong with the following code?

int test=1;

while(test!=EOF){

test=fscan(fileIn, "%d", value);

fprintf(fileout, "The next value ism%d\n", value);

}

a) we have read past the end of the input file and output one garbage value

b) we have nothing written past the end of the output file

c) nothing

d) a and b

We have read past the end of the input file and output one garbage value

34
New cards

The function isalpha (arg) returns

Returns true if arg is an alphabetical character

35
New cards

The command fprintf(outfile, “%.2f”, x)

Outputs the floating point value x sent to outFIle with 2 decimal places changing the value of x

36
New cards

After a file is opened, before the FILE pointer is used for input and output, it should be

Checked to see if it is opened correctly

37
New cards

The command fprint(outFile, “%5d”, x) is used to 

Display the integer x in at least 5 characters

38
New cards

What is the output of the following code?

char ch= ‘G’;

printf(“%d\n”, tolower(ch));

The integer value of ‘g’

39
New cards

Which of the following is the correct way to close a file referred to by the FILE pointer variable named outFile? 

fclose(outFile)

40
New cards

Which of the following loop condition statements will read all the data in the file assuming that each record in the file is two integer values, and you will read the first one into a variable named intOne, and the other into intTwo? 

while(fscanf(inFile, “%d%d”, &intOne, &intTwo)==2)

41
New cards

THe formatting options that were discussed for printf do not work for fprintf

False

42
New cards

‘\n’ is two characters 

False

43
New cards

FOPEN_MAX is a macro defined in stdlib.h

False

44
New cards

You may have as many files open as you would like

False

45
New cards

The fgets function will stop reading in characters if it encounters any whitespace character or the end of file and makes sure that you cannot read more characters than indicated by the max parameter 

False 

46
New cards

You may not have more than file open at any one time

False

47
New cards

The function gets is designed to read a c-string from standard input but is considered unsafe and should not be used because you do not list the buffer size in the argument list

True

48
New cards

Since the type FILE is an opaque object type and we only interact with it through pointers and functions, we should never dereference a FILE pointer

True

49
New cards

FILE pointers may be passed to a function

True

50
New cards

You must use a field width specifier in each format specifier that you want output in a certain field

False

51
New cards
52
New cards
53
New cards
54
New cards
55
New cards
56
New cards
57
New cards
58
New cards
59
New cards
60
New cards
61
New cards
62
New cards
63
New cards
64
New cards
65
New cards
66
New cards
67
New cards