Well I broke it down even simpler with this and I still am getting strange results full of zeros.
Code:
Sam Smith N 12.5000 13.5000 8.00 GA 15.75 300 \n
Sam Collins N 15.0000 11.2500 8.00 AL 12.00 300 \n
Cathy Smith Y 10.5000 14.0000 9.00 SC 15.99 300 \n
EOF
and here's the code I've been using and trying to fix.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void){
char ch;
float l;
float w;
float h;
int area;
char sDay;
char state[3];
char cName[21];
char line[94];
char buffer[94];
FILE *fp;
fp = fopen("txTDsale.fil", "r");
if(fp == NULL)
printf("could not open file\n");
setvbuf(fp, buffer, _IOLBF, 94);
//while((ch = getc(fp)) != '\n');
//this one works fine for printing to screen but can't store data
//fgets(line, sizeof(line), fp);
//fscanf(fp, "%20[^\n]%10c%10f%10f%10f%10s%%10f%10d)", cName, &sDay, &l, &w, &h, &state, &area);
fscanf(fp, " %20[^\n] %c %f %f %f %s %f %d [^\n]", cName, &sDay, &l, &w, &h, &state, &area);
printf("%s %c %f %f %f %s %d %f %d\n", cName, sDay, l, w, h, state, area);
printf("%s\n", line);
//fgets(line, sizeof(line), fp);
//printf("%s \n", line);
return 0;
}
I have been having a terrible time getting scanf and fscanf functions to work.
I don't know if I'm misinterpreting the syntax or what I'm doing wrong.
Can anyone help?
Mr. Deeds