Hi,
I know I am not done with this, but I get an error that I don't know how to fix.
I am trying to lower the inventory count of this data file.
named productdata.txt
id, price, and count
Code:
0 0.00 99 1 1.00 10 2 2.00 20 3 3.00 30 4 4.00 40 5 5.00 50 6 6.00 60 7 7.00 70 8 8.00 80 9 9.00 90
I wrote this:
to get into and do the work:
Code:
#include <stdio.h>
#include <stdlib.h>
#include "product.h"
#define IDSize 4
#define PriceSize 5
#define CountSize 3
#define RecordSize (IDSize+PriceSize+CountSize)
int main ( int argc, char** argv )
{
int count;
int currentID;
int inputID;
FILE *myfile;
int set;
int i;
int oldCount;
//fgets( FileName, sizeof( FileName ), stdin );
//if( FileName[strlen( FileName ) - 1] == '\n' )
//{
// FileName[strlen( FileName ) - 1] = '\0';
//}
myfile = fopen(FileName, "r");
if (myfile == NULL)
{
printf("Cannot open %s\n", FileName);
return(1);
}
printf( "Enter the ID of the product you wish to change: ");
scanf( " %d", &inputID);
for( i = 0; i < NumProducts; i++ )
{
if( inputID == Product[i].id )
{
break;
}
}
while(1)
{
set = fscanf( FileName, "%d", currentID);
if (set == 0)
{
break;
}
if( currentID == inputID )
{
fseek( FileName, PriceSize, SEEK_CUR );
fscanf( FileName, " %d", &count);
count--;
oldCount = count;
fseek( FileName, -CountSize, SEEK_CUR );
fprintf( FileName, "%3d", count);
break;
}
fseek( FileName, PriceSize + CountSize , SEEK_CUR );
}
printf( "Count of product ID %d changed from %d to %d\n", inputID, oldCount , count);
return (0);
}
I was given this header to include as is:
Code:
#define FileName "productdata.txt"
#define NumProducts 10
#define RecordSize (4+5+3)
struct Product
{
int id; // four-digit product ID code
float price; // xx.xx product price (5 characters)
int count; // three-digit count of units in stock
};
typedef struct Product Product;
I am getting an error at:
Code:
if( inputID == Product[i].id )
won't compile and gives error:
syntax error before "Product"
I am confused.
As I said I know the program is not done yet but it will compile if I comment out:
Code:
for( i = 0; i < NumProducts; i++ )
{
if( inputID == Product[i].id )
{
break;
}
}
Which obviously includes the problem code.
Am I supposed to reference the header file?