![]() |
| | #16 | |
| CSharpener Join Date: Oct 2006
Posts: 5,242
| Quote:
fscanf reads from the "indata.txt" what it has to do with your pressing enter?
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. | |
| vart is offline | |
| | #17 |
| Registered User Join Date: Mar 2009
Posts: 11
| 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 ... |
| ali_1234 is offline | |
| | #18 |
| CSharpener Join Date: Oct 2006
Posts: 5,242
| post your last code
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. |
| vart is offline | |
| | #19 |
| Registered User Join Date: Mar 2009
Posts: 11
| 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;
}
}
}
|
| ali_1234 is offline | |
| | #20 |
| CSharpener Join Date: Oct 2006
Posts: 5,242
| 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;
}
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. |
| vart is offline | |
| | #21 |
| Registered User Join Date: Mar 2009
Posts: 11
| 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 !! |
| ali_1234 is offline | |
| | #22 | |
| CSharpener Join Date: Oct 2006
Posts: 5,242
| Quote:
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. | |
| vart is offline | |
![]() |
| Tags |
| c programming, home work, input output, min and max, minimum and maximum |
| Thread Tools | |
| Display Modes | |
|