Module 12: C Language Files (Basic I/O) Flashcards

1
Q

file

A

logical collection of 1’s and 0’s; all files are truly binary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

file system

A

provides an overall context for organizing and naming the files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

text (aka ASCII) files

A

1s and 0s in the file are encoded in ASCII, making it a plain printable text that is generally human readable and editable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

binary files

A

1s and 0s are encoded in a format other than ASCII. the format is generally created by the programmer. generally not human-readable or editable i.e. looks like garbage. usually generated and interpreted by some program. this name is a misnomer because all files are truly binary; it should be called non-ASCII to refer to “everything else”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

FILE

A

a structure type that holds information about an open file.

information like place in the file system, our position in the file, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

to open/close a file:

A

fopen(): helper function to open a file

fclose(): helper function to close a file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

to read/write 1 character aka a byte from/to a file

A

fgetc(): reads character from a file and advances position indicator

fputc(): writes character to a file and advances position indicator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

to read/write 1 line as a string from/to a file

A

fgets(): reads a string from a file and stores it in string. stops reading when n-1 characters are read, when the newline character is read, or EOF

fputs(): writes a string to a file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

to read/write multiple bytes from/to a file

A

fread(): reads data from a file into an array

fwrite(): writes data from an array into a file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

to read/write formatted strings from/to a file (or a string itself):

A

fprintf(): writes formatted string to a file
fscanf(): reads formatted string from a file
sscanf(): reads formatted data from a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

helpful ways to tell if you are at the end of a file:

A
EOF: actually a typedef for "-1"
you can compare the return of functions like fgetc() to EOF to see if you've reached the end of a file
int feof(FILE *f): a function that you can call to see if you are at the end of a file. returns 1 if you've reached the end of a file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

3 special files that are automatically opened for all C programs:

A

stdin, stdout, and stderr

the programmer does not need to call fopen() or fclose() on these files

these special files aren’t really files; they are I/O devices! they represent the I/O devices of the keyboard and the ASCII display (the normal one and a special “error” display. these files are consistent with the idea that C is indeed “file-oriented”, meaning that it treats I/O devices no differently from files. you can pass these open devices to all of the file functions we’ve studied in this lecture.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

3 I/O connected devices:

A

stdin: standard input (console)
stdout: standard output (console, for output)
stderr: standard error (console, for error message)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

arguments to main

A

argc: number of strings on the command line (argc >= 1)
argv: list of strings containing all of these words
- -> note the declaration of argv as a pointer to an array of pointers; double dereferencing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly