f-scanf into different data type arrays
Hi there, i am new to C and programming and while learning File I\o and arrays i am required to scan in 3 different types of data from a file and store them in arrays.
I believe my code is right but when i try to check if my arrays contain any data by printing them out i get nothing.
what am i missing here?
Code:
#include<stdio.h>
#include<string.h>
#defineSIZE120
int main(int argc, char *argv[])
{
char line, *nameArray;
int i, age, ageArray, counter = 0;
float wage, wageArray;
FILE *srcFile;
srcFile = fopen(argv[1], "r");
if (srcFile == NULL) {
printf("Error, no file was opened.\n");
fclose(srcFile);
return (0);
} else {
printf("File was successfully opened.\n");
}
while (fscanf(srcFile, "%s%d%f\n", nameArray, &ageArray, &wageArray) != EOF) {
nameArray = line;
ageArray = age;
wageArray = wage;
i++;
counter++;
}
for (i = 0; i < counter; i++) {
printf("%s%d%.2f", nameArray, ageArray, wageArray);
}
printf("\n%d lines", counter);
fclose(srcFile);
return (0);
}