CS 36 Unit 3 Study GUide Flashcards

1
Q

What is the format for fopen and what does it do

A

The format for fopen is fopen(“filename.exe”, “w”); and it basically creates a new file if it doesn’t exist but if it does exist then it is opened through the write format, meaning you can add stuff inside of it

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

What do you set equal to fopen and whatnot?

A

You do FILE *fPtr = fopen(“filename.exe”, “w”); and then if it doesn’t open then it is equal to NULL

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

How to open a file in binary format? How to add stuff into the binary file?

A

You do fopen(“filename.exe”, “wb”); Binary file is best when you have a struct of data and you want to implement it in the file. Then, you would fill a struct with blank info, (if typedef you would do name and then variable, if not struct name and then variable). You would set the variable equal to what is in the structure’s variables.

From there, you would do fwrite(&variableName, sizeof(struct name), 1, pointer);

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

fclose

A

Whenever you open a file, you would have to close it through this. You would do fclose(ptrName);

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

What is the fopen format to update already existing information in a binary file?

A

instead of fopen(“filename.exe”, “wb”);
You would do fopen(“filename.exe”, “rb+”);
And then you would do fseek(pointerFile, sizeof(struct name) * (variablestruct.dataFromStruct - 1), SEEK_SET)(this places the pointer at the beginning of the file)

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

What does fprintf do and how does that differ from fwrite?

A

fprintf is like fwrite but it is used in a regular file. Basically, you would have to do fprintf(fileName, “%datatype %datatype\n”, variable name, variable name2); This would write this text into the file

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

What does fscanf do?

A

fscanf has three different parameters. fscanf(pointerName, “%datatype%datatype%datatype, &variable, &variable, variable(if this is character variable). This function can be used if the file is opened in read, and changes current variable values.

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

What are the three different file access modes?

A

wb, rb+ and wb+. wb is used to open/create files, as well as writing initial information, rb+ is used to change information in the file, and wb+ is used to read the file and print information

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

feof(review this)

A

Looks until the rest of the file for NULL

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

rewind

A

For normal files, this makes the cursor go back to the beginning, unlike fseek(pointer name, (function name.variable - 1) * (sizeof(struct name), SEEK_SET (start of the file, where the cursor starts in the file)

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

What are the three different reasons to use interface and implementation header files(create our own?)

A

Solve specific tasks, share code with others, and hide implementation (reusability, portability, security)

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

What are the different include guards

A

ifndef STACK_H

#define STACK_H
#endif

it checks if it is not defined, then it defines if it isn’t, and then it ends the thing

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