C Programming - Input / Output - Discussion
Discussion Forum : Input / Output - Find Output of Program (Q.No. 12)
12.
What will be the output of the program ?
#include<stdio.h>
int main()
{
FILE *fp;
char ch, str[7];
fp=fopen("try.c", "r"); /* file 'try.c' contains "This is Nagpur" */
fseek(fp, 9L, SEEK_CUR);
fgets(str, 5, fp);
puts(str);
return 0;
}
Discussion:
30 comments Page 3 of 3.
Thilaga said:
1 decade ago
@Sintu: you said remaining 4 char was printed. But there the remaing char is 5.
So 5 has it print but it print 4 char oly .........
So 5 has it print but it print 4 char oly .........
Preety said:
1 decade ago
What does the 9L means in the code?
Can anybody please tell me abt seek_cur, seek_set, seek_end?
Can anybody please tell me abt seek_cur, seek_set, seek_end?
Cindrella said:
1 decade ago
Please provide me a detailed description on fseek and fgets.
Sintu Kumar Das said:
1 decade ago
In the file the 7th character is 'N' and fgets reads n-1 character.so r is not printed.After 7 character,str gets the null character and stoped. So the remaining 4 will be printed.
RAHUL said:
1 decade ago
What about fseek guys?
Baadal said:
1 decade ago
Function fgets(char *s,int n ,FILE char *stream)
It stop when it read n-1 char or a newline whichever come first.
Hence in the given question it read only 4 char.
It stop when it read n-1 char or a newline whichever come first.
Hence in the given question it read only 4 char.
Sai said:
1 decade ago
@viraj.
That is will it take 4 chars when 5 chars are said to be taken in fgets?
That is will it take 4 chars when 5 chars are said to be taken in fgets?
Gouthami said:
1 decade ago
We want more explanation.
Vikas Sharma said:
1 decade ago
Thanks bro!
Viraj said:
1 decade ago
fgets prototype :char * fgets(char *str,int n,FILE *fp)
fgets reads n-1 characters or till it encounters \n in input whichever comes firsts
fgets reads n-1 characters or till it encounters \n in input whichever comes firsts
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers