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 2 of 3.
Jogamohan Medak said:
1 decade ago
Offset used in fseek() function call can be a negative number.
It makes the file pointer to move backwards from the current position.
It makes the file pointer to move backwards from the current position.
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 .........
Aditi said:
1 decade ago
If fp points to the 9th character in the string which is N then why fgets is not reading 'N'. Please someone provide me the reason.
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?
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?
Tnareju said:
1 decade ago
seek_cur it sets pointer (fp) currently to 9L (9 th char of that line i.e N)
Sindhu said:
1 decade ago
Please explain these two lines:
fseek(fp, 9L, SEEK_CUR);
fgets(str, 5, fp);
fseek(fp, 9L, SEEK_CUR);
fgets(str, 5, fp);
Cindrella said:
1 decade ago
Please provide me a detailed description on fseek and fgets.
AMOL said:
1 decade ago
@Preety: 9L means it move forward 9 char before printing.
Chandu said:
9 years ago
How can I get the answer agpur?
Can anyone explain me?
Can anyone explain me?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers