Hey i have written a program that is supposed to parse the ":" out of a data file and it compiles fine with no errors or anything but when it prints the output it is harshly incorrect so obviously i have the input from the file programed wrong or the parsing messed up any help would be appreciated!! Thanks.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "program8.h"
//structure declaration
int main()
{
PAINT mypaint[20];
char Input[100];
FILE* infile= fopen("paint.data","r");
if(!infile)
{
printf("Could not open file");
exit(1);
}
getData (mypaint, infile, Input);
printData (mypaint);
return 0;
}
void getData(PAINT* mypaint, FILE* infile,char* Input)
{
int i;
fgets(Input, sizeof(Input), infile);
for(i = 0; i < 5; i++)
{
sscanf(Input, "%s[^:] %c[^:] %d[^:] %f", mypaint[i].color, &mypaint[i].size, &mypaint[i].qty, &mypaint[i].price);
}
return;
}
void printData (PAINT* mypaint)
{
int i;
for (i=0; i<4; i++)
{
printf("%s %c %d %f \n\n", mypaint[i].color, mypaint[i].size, mypaint[i].qty, mypaint[i].price);
}
return;
}