[plug] C, bad syntax etc.
John Knight
anarchist_tomato at hotmail.com
Mon Nov 18 17:21:02 WST 2002
G'day all! I'm having quite a few probs with file i/o here, would someone
be able to troubleshoot this code?
#include <stdio.h>
#include <math.h> //i'm whacking in anything i can think of here
#include <string.h>
#include <stdlib.h>
/* whole number storage programme, lecture 16, question 1*/
FILE *fptr;
main()
{
int number[10];
int count = 0;
printf("\nEnter your 1st number: ");
scanf("%d",&number[0]);
printf("\nEnter your 2nd number: ");
scanf("%d",&number[1]);
printf("\nEnter your 3rd number: ");
scanf("%d",&number[2]);
printf("\nEnter your 4th number: ");
scanf("%d",&number[3]);
printf("\nEnter your 5th number: ");
scanf("%d",&number[4]);
printf("\nEnter your 6th number: ");
scanf("%d",&number[5]);
printf("\nEnter your 7th number: ");
scanf("%d",&number[6]);
printf("\nEnter your 8th number: ");
scanf("%d",&number[7]);
printf("\nEnter your 9th number: ");
scanf("%d",&number[8]);
printf("\nEnter your 10th number: ");
scanf("%d",&number[9]);
do
{
fptr = (fopen ("num.dat", "wa+"));
fprintf(fptr, " %d", number[count]);
//flcose (fptr);
count++;
}
while (count < 9);
return 0;
I'm having two problems here, one is that when I read num.dat, it's only
taking in the first number, I assume the 'count' loop isn't working
properly?
The second problemis fclose(fptr); isn't working, gcc reckons that fclose is
an undeclared variable, shouldn't it work with the headers I gave it? What
must I do?
Tah for your help. :)
Make lunch, not war.
_________________________________________________________________
Add photos to your e-mail with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail
More information about the plug
mailing list