i am getting an output file now but the problem is min value is always zero and max mum value is some number...0814...
now again im stuck ...
Code:#include <stdio.h> int main () { int i,a[10],val,n=0,max,min; FILE *fi,*fo; if((fi=fopen("indata.txt","r"))==NULL) { printf("Error in opening the file!!!\n"); return 1; } else { while(fscanf(fi,"%d",&val)) { a[n]=val; n=(n+1); printf("%d %d\n", val, n); getch (); max = a[0]; min = a[0]; for (i = 0; i <= 10; i++) { if (a[i] > max) { max = a[i]; } else if (a[i] < min) { min = a[i]; } } if((fo=fopen("result.txt","w"))==NULL) { printf("Error in opening the file!!!\n"); return 1; } else { fprintf (fo,"Maximum element in an array : %d\n", max); fprintf (fo,"Minimum element in an array : %d\n", min); } fclose(fo); fclose(fi); getchar (); return 0; } } }
your indentetion suxx big deal - you do not even see simplest bugs
also - when you have return inside if - you do not need else - it just adds unneded indentation level
Code:#include <stdio.h> int main (void) { int i,a[10],val,n=0,max,min; FILE *fi,*fo; if((fi=fopen("indata.txt","r"))==NULL) { printf("Error in opening the file!!!\n"); return 1; } while(fscanf(fi,"%d",&val) == 1) { a[n]=val; n=(n+1); printf("%d %d\n", val, n); if(n == 10) break; } max = a[0]; min = a[0]; for (i = 0; i <= 10; i++) { if (a[i] > max) { max = a[i]; } else if (a[i] < min) { min = a[i]; } } if((fo=fopen("result.txt","w"))==NULL) { printf("Error in opening the file!!!\n"); return 1; } fprintf (fo,"Maximum element in an array : %d\n", max); fprintf (fo,"Minimum element in an array : %d\n", min); fclose(fo); fclose(fi); getchar (); return 0; }
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
thanks people for ur kind support ...
and vart i am really sorry i am jus a beginner and my programming teacher sux .. so i dont know a damn about it .. wht evr i have studied is by my self ... i m really thank full for ur support cudn't do this without u ppl !!!..
THANK YOU PPL !!!!........... spl VART !!