Connecting to the real world: files and streams M7 Test
-
What happens if you try to compile and run this program assuming that the
fopen()
function operation succeeds?#include <stdio.h> int f(char t[]) { return t[0] - t[-1]; } int main(void){ int i = 2; i -= f("ABDGK" + 1); printf("%d", i); return 0; }
- the program outputs
12A
- the program outputs
12
- the program outputs
1
- the compilation or the execution fails
- the program outputs
-
What happens if you try to compile and run this program assuming that the
fopen()
function operation succeeds?#include <stdio.h> int main(void){ FILE *f = fopen("file", "w"); char c; fputs("12A", f); fclose(f); f = fopen("file", "r"); fscanf(f, "%c", &c); fclose(f); printf("%c", c); return 0; }
- the program outputs
1
- the compilation or the execution fails
- the program outputs
12A
- the program outputs
12
- the program outputs
-
What happens if you try to compile and run this program assuming that the
fopen()
function operation succeeds?#include <stdio.h> int main(void){ FILE *f = fopen("file", "w"); int i; fputs("12A", f); fclose(f); f = fopen("file", "r"); fseek(f); i = ftell(f, 0, SEEK_END); fclose(f); printf("%d", i); return 0; }
- the program outputs
2
- the program outputs
3
- the compilation or the execution fails
- the program outputs
1
- the program outputs
-
What happens if you try to compile and run this program assuming that the
fopen()
function operation succeeds?#include <stdio.h> int main(void) { FILe *f = fopen("file", "w"); int i = fputs("Hello!", f); printf("%d", i != EOF); return 0; }
- the program outputs
2
- the compilation or the execution fails
- the program outputs
0
- the program outputs
1
- the program outputs
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { int i; i = fprintf(stdin, "HELLO!"); printf("%d", i == EOF); return 0; }
- the program outputs
2
- the program outputs
1
- the program outputs
0
- the compilation or the execution fails
- the program outputs
-
What happens if you try to compile and run this program assuming that the
fopen()
function operation succeeds?#include <stdio.h> int main(void) { FILE *f = fopen("file", "w"); int i = fputs(f, "HELLO!"); printf("%d", i != EOF); fclose(f); return 0; }
- the program outputs
2
- the compilation or the execution fails
- the program outputs
1
- the program outputs
0
- the program outputs
-
What happens if you try to compile and run this program assuming that the
fopen()
function operation succeeds?#include <stdio.h> int main(void) { FILE *f = fopen("file", "w"); int i; fputs("12A", f); fclose(f); f = fopen("file", "r"); fseek(f, 0, SEEK_END); i = ftell(f); fclose(f); printf("%d", i); return 0; }
- the program outputs
1
- the program outputs
2
- the compilation or the execution fails
- the program outputs
3
- the program outputs
-
The following string:
D:\USERDIR\jonhdoe.txt
is a valid file name in:
- MS Windows systems
- Unix/Linux systems
-
What happens if you try to compile and run this program assuming that the
fopen()
function operation succeeds?#include <stdio.h> int main(void) { char s[20]; FILE *f = fopen("file", "w"); int i = fputs("12A", f); fclose(f); f = fopen("file", "r"); fgets(s, 2, f); puts(s); fclose(f); return 0; }
- the program outputs
12
- the compilation or the execution fails
- the program outputs
1
- the program outputs
12A
- the program outputs
-
What happens if you try to compile and run this program?
#include <stdio.h> int i = 0; int *f(int *i) { (*i)++; return i; } int main(void) { int i = 1; i = *f(&i); printf("%d", i); return 0; }
- the program outputs
2
- the program outputs
1
- the compilation or the execution fails
- the program outputs
0
- the program outputs
-
The following string:
#HomeDir/HomeFile
is a valid file name in:
- MS Windows systems
- Unix/Linux systems
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { FILE *f = fopen("file", "w"); float f; fputs("12A", f); fclose(f); f = fopen("file", "r"); fscanf(f, "%f", &f); fscanf(f); printf("%f", f); return 0; }
- the program outputs
0.000000
- the program outputs
12.000000
- the program outputs
1.000000
- the compilation or the execution fails
- the program outputs
-
Unix/Linux system treat the following file names:
JohnDone
andJohndone
as:
- identical file names
- different file names
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { char s[20]; FILE *f = fopen("file", "w"); int i = fputs("12A", f); fclose(f); f = fopen("file", "r"); fgets(s, 20, f); puts(s); fclose(f); return 0; }
- the program outputs
12A
- the program outputs
12
- the program outputs
1
- the compilation or the execution fails
- the program outputs
-
What happens if you try to compile and run this program?
int main(void) { FILE *f; f = fopen("file", "wb"); printf("%d", f != NULL); fcolse(f); return 0; }
- the compilation fails
- the program outputs
0
- the program outputs
1
- the execution fails
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { FILE *f; f = fopen("file", "wb"); printf(%d, f != NULL); fcolse(f); return 0; }
- the program outputs
2
- the compilation fails
- the program outputs
1
- the program outputs
0
- the program outputs
-
The following string:
JohnDoe
is a valid file name in:
- MS Windows system only
- Unix/Linux and MS Windows system
- Unix/Linux system only
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { FILE *f; int i = fprintf(f, "Hello!"); printf("%d", i == EOF); return 0; }
- the program outputs
1
- the program outputs
2
- the program outputs
0
- the compilation or the execution fails
- the program outputs
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { int i; i = fprintf(f, "Hello!"); printf("%d", i == EOF); return 0; }
- the program outputs
0
to thestdout
stream - the program outputs
1
to thesttout
strezm - the compilation or the execution fails
- the program outputs
2
to thestdout
stream
- the program outputs
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { FILE f; f = fopen("file", "wb"); printf("%d", f != NULL); fcolse(f); return 0; }
- the compilation fails
- the program outputs
1
- the program outputs
0
- the execution fails
Subscribe
0 Comments
Newest