There were 10 records stored in “somefile.dat” but the
following program printed 11 names. What went wrong?
void main()
{
struct student
{
char name[30], rollno[6];
}stud;
FILE *fp = fopen(“somefile.dat”,”r”);
while(!feof(fp))
{
fread(&stud, sizeof(stud), 1 , fp);
puts(stud.name);
}
}
Answer / susie
Explanation:
fread reads 10 records and prints the names successfully. It
will return EOF only when fread tries to read another record
and fails reading EOF (and returning EOF). So it prints the
last record again. After this only the condition feof(fp)
becomes false, hence comes out of the while loop.
| Is This Answer Correct ? | 2 Yes | 4 No |
main() { extern i; printf("%d\n",i); { int i=20; printf("%d\n",i); } }
#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d",s->x); printf("%s",s->name); }
To reverse an entire text file into another text file.... get d file names in cmd line
write a program to find out roots of quadratic equation "x=-b+-(b^2-4ac0^-1/2/2a"
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.
6 Answers Fusion Systems GmbH,
void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); printf("%u \n",gotit=--giveit); }
create a login program that ask username and password. if you input username or password 3 times wrong, the program will terminate else the program will prompt a message "congratulations"
void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }
char inputString[100] = {0}; To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString, sizeof(inputString), fp)
why nlogn is the lower limit of any sort algorithm?
void main() { int *mptr, *cptr; mptr = (int*)malloc(sizeof(int)); printf(“%d”,*mptr); int *cptr = (int*)calloc(sizeof(int),1); printf(“%d”,*cptr); }
how can u draw a rectangle in C
53 Answers Accenture, CO, Codeblocks, Cognizant, HCL, Oracle, Punjab National Bank, SAP Labs, TCS, University, Wipro,