Hi, it's me again. *waves* I'm having some trouble, and I could really use a fresh set (or sets) of eyes.
This program is supposed to take two lists of integers of the same length ended by -1 and store them in two arrays, x and y, which each have 20 elements. The lists are not necessarily 20 numbers long. There's more after that, but it seems most likely that the problem is in my read_file function:
Code:
#define SENTINEL -1
void read_file(int x[20], int y[20], int *count){
FILE *fp;
char filename[80], skip_ch;
int value, status, i;
printf("Please enter the file name>> ");
scanf("%s", &filename);
scanf("%c", &skip_ch); //eat \n
fp = fopen(filename, "r");
status=fscanf(fp, "%d", &value);
for(i=0; value!=SENTINEL && status==1 && i<20; i++){
x[i]=value;
status=fscanf(fp, "%d", &value);
}//read first line into x[]
if(status!=1 || value==SENTINEL){
do{
fscanf(fp, "%c", &skip_ch);
}while(skip_ch!='\n');
}//if status!=1 || value==SENTINEL
for(i=0; value!=SENTINEL && status==1 && i<20; i++){
y[i]=value;
status=fscanf(fp, "%d", &value);
}//read second line into y[]
*count=i;
}//read_file
int main()
{
int x[20], y[20], z[20], count;
read_file(x, y, &count); //prompts for a file name and reads the file into the two arrays
multiply_arrays(x, y, z, count); //multiplies x and y and puts the results in z
display_arrays(x, y, z, count); //displays the three-column table
z_sqrt(z, count); //computes the sum of z, then displays the sum and its square root
return 0;
}//main
Here's the output I get on running it:
Code:
teyla:~ quasigreat$ cat lists1.dat
10 2 3 17 18 -1
99 8 26 35 40 -1
teyla:~ quasigreat$ ~quasigreat/a.out
Please enter the file name>> lists1.dat
The sqrt of 0 is 0.00
Help is much appreciated.