C Programming :: File Input/Output

NA
SHSTTON
1
Solv. Corr.
2
Solv. In. Corr.
3
Attempted
0 M:0 S
Avg. Time

1 / 12

What is the output of the following 'C' program ?

#include
void main()
{
FILE *ptr;
char i;
ptr=fopen("abc","r");
while((i=fgets(ptr))!=EOF)
printf("%c",i);
}


Acontents of abc followed by an infinite loop

BCompilation Error

CContents of abc

DNone of these

Answer: Option A

Explanation:

The condition is checked against EOF, it should be checked against NULL.

Workspace

NA
SHSTTON
0
Solv. Corr.
3
Solv. In. Corr.
3
Attempted
0 M:0 S
Avg. Time

2 / 12

If the content of a file (input) is abc def. What will be the value of input and ch?.

#include
char input[100],ch;
void main(void)
{
FILE *fp;
fp = fopen("input","rb");
fscanf(fp, "%s" ,&input);
fscanf(fp, "%c" ,&ch);
printf("%s %c", input, ch);
}


Aabc d

Babc def

Cabc

DNone of these

Answer: Option C

Explanation:

It will not scan anything after a space is encountered. 

Workspace

NA
SHSTTON
1
Solv. Corr.
3
Solv. In. Corr.
4
Attempted
0 M:0 S
Avg. Time

3 / 12

If a file contains the line "I am an Indian\r\n" then on reading this line into the array str using fgets().
what would str contain?


A"I am an Indian\r\n\0"

B"I am an Indian\n\0"

C"I am an Indian\r\0"

D"I am an Indian"

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
1
Solv. Corr.
2
Solv. In. Corr.
3
Attempted
0 M:0 S
Avg. Time

4 / 12

In the following 'C' code, fp points to

#include
void main()
{
FILE* fp;
fp = fopen ("trial", "r");
}


Afirst character in the file

BA structure which contains a char pointer which point to the first. chs meter in th file

Cname of the file

DNone of these

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
1
Solv. Corr.
2
Solv. In. Corr.
3
Attempted
0 M:0 S
Avg. Time

5 / 12

In the following statement, the variable fpt is

fprintf(fpt, "%n", i);


Aa character variable

Barbitrarily assigned a value.

Ca pointer to a file

Da special kind of variable called

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
0
Solv. Corr.
3
Solv. In. Corr.
3
Attempted
0 M:0 S
Avg. Time

6 / 12

The function fopen ("filename","r") returns


ANothing

Ba value 0 or 1 depending on whether the file could be opened or not.

Ca pointer to FILE filename, if it exits

Da pointer to a new file after creating it.

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
1
Solv. Corr.
3
Solv. In. Corr.
4
Attempted
0 M:0 S
Avg. Time

7 / 12

The expression ((fpt = fopen ("Samples", "w")) == NULL) would be true if


Athe file sample does not exist while fopen is being executed

Bthe file "sample" could not be created for writing

Cfpt is not deeclared as a FILE pointer

Dthe file "sample" is read only

Answer: Option B

Explanation:

This is because here 'w' means it truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. But, it is null hence, the file "sample" could not be created for writing.

Workspace

NA
SHSTTON
0
Solv. Corr.
1
Solv. In. Corr.
1
Attempted
0 M:0 S
Avg. Time

8 / 12

In mulit-list organization


ARecords that have equivalent value for a given secondary index item are linked together to form a list

BRecords are loaded in ordered sequence defined by collating sequence by content of the key

CRecords are directly accessed by record key field

DNone of the above

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
2
Solv. Corr.
1
Solv. In. Corr.
3
Attempted
0 M:0 S
Avg. Time

9 / 12

Which of the following is/are advantages of cellular partitioned structure:


ASimultaneous read operations can be overlapped

BSearch time is reduced

CBoth a & b

DNone of the above

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
1
Solv. Corr.
2
Solv. In. Corr.
3
Attempted
0 M:0 S
Avg. Time

10 / 12

x = fopen (b, c) what is b?


Apointer to a character array which contains the filename

Bfilename whithin double quotes

Ccan be anyone of the above

DNone of the above

Answer: Option C

Explanation:

Here is no explanation for this answer

Workspace