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 |
write a c program to Reverse a given string using string function and also without string function
main() { char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); }
Cluster head selection in Wireless Sensor Network using C programming language.
/*what is the output for*/ void main() { int r; printf("Naveen"); r=printf(); getch(); }
programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h
Who could write how to find a prime number in dynamic array?
Write a routine that prints out a 2-D array in spiral order
main() { unsigned int i=10; while(i-->=0) printf("%u ",i); }
main() { char *p; printf("%d %d ",sizeof(*p),sizeof(p)); }
main() { int i; clrscr(); for(i=0;i<5;i++) { printf("%d\n", 1L << i); } } a. 5, 4, 3, 2, 1 b. 0, 1, 2, 3, 4 c. 0, 1, 2, 4, 8 d. 1, 2, 4, 8, 16
Sir... please give some important coding questions asked by product companies..
void main() { int c; c=printf("Hello world"); printf("\n%d",c); }