MCQs
Which of the following statement is correct about the program?
#include<stdio.h>
int main()
{
FILE *fp;
char str[11], ch;
int i=0;
fp = fopen("INPUT.TXT", "r");
while((ch=getc(fp))!=EOF)
{
if(ch == '\n' || ch == ' ')
{
str[i]='\0';
strrev(str);
printf("%s", str);
i=0;
}
else
str[i++]=ch;
}
fclose(fp);
return 0;
}
This program reads the file INPUT.TXT and store it in the string str after reversing
the string using strrev function.
This program counts the number of lines in the file myfile.c by counting the character '`setminus`n' in that file.
The path of file name must be given as "c: `setminus` `setminus` tc `setminus`file.c"
Instead of "20" use 20L since fseek() need a long offset value.
This program tries to open the file trial.txt in read mode. If file not exists or unable to
read it prints "Unable to open file" and then terminate the program.
If file exists, it simply close the file and then terminates the program.
The scanf function returns the number of input is given.
printf("%d`setminus`n", scanf("%d", &i)); The scanf function returns the value 1(one).
Therefore, the output of the program is '1'.
int a=250; The variable a is declared as an integer type and initialized to value 250.
printf("%1d`setminus`n", a); It prints the value of variable a.
Hence the output of the program is 250.