C Programming Questions and Answers:: Input / Output

On executing the below program what will be the contents of 'target.txt' file if the source file contains a line "To err is human"?


int main()
    int i, fss;
    char ch, source[20] = "source.txt", target[20]="target.txt", t;
    FILE *fs, *ft;
    fs = fopen(source, "r");
    ft = fopen(target, "w");
            fseek(fs, 4L, SEEK_CUR);
            fputc(ch, ft);
    return 0;
A. r n
B. Trh
C err
D. None of above

To scan a and b given below, which of the following scanf() statement will you use?


float a;
double b;
A. scanf("%f %f", &a, &b);
B. scanf("%Lf %Lf", &a, &b);
C scanf("%f %Lf", &a, &b);
D. scanf("%f %lf", &a, &b);

Consider the following program and what will be content of t?


int main()
    FILE *fp;
    int t;
    fp = fopen("DUMMY.C", "w");
    t = fileno(fp);
    printf("%d\n", t);
    return 0;
A. size of "DUMMY.C" file
B. The handle associated with "DUMMY.C" file
C Garbage value
D. Error in fileno()

Which files will get closed through the fclose() in the following program?


int main()
    FILE *fs, *ft, *fp;
    fp = fopen("A.C", "r");
    fs = fopen("B.C", "r");
    ft = fopen("C.C", "r");
    fclose(fp, fs, ft);
    return 0;
A. "A.C" "B.C" "C.C"
B. "B.C" "C.C"
C "A.C"
D. Error in fclose()

To print out a and b given below, which of the following printf() statement will you use?


float a=3.14;
double b=3.14;
A. printf("%f %lf", a, b);
B. printf("%Lf %f", a, b);
C printf("%Lf %Lf", a, b);
D. printf("%f %Lf", a, b);

Page 1 of 4