Hi I kinda forgot my old account for this forum coomunity and I wanted to post a problem about the POS I am developing with C.

The program allows you to read a certain file (inventory.ini) , add items to it, view the items, edit contents and delete.

Here is my code for my main program (pos2.c)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "inventory.h"

char temp,newcode[6],newdesc[10],stemp[10];
int numrec,x,y,z, choice;
float newprice;

int initial();
int add_itemcode();
int add_itemdesc();
int add_itemprice();
int listofallitems();
int deleteitem();
int edit_price();
int edit_desc();
int edit_code();
int edit_task();


main()
{
    
    system("cls");
    printf("--------MENU--------");
    printf("[1] Add Inventory\n");
    printf("[2] Edit Inventory\n");
    printf("[3] Delete Inventory\n");
    printf("[4] List All Inventories\n");
    printf("[0] Exit System\n\\");
    printf("Enter MENU : ");
    scanf("%d", &choice);

        switch(choice)
        {
            case 1 : system("cls");
                     printf("--------Add Inventory--------\n");
                     initial();
                     add_itemcode();
                     getch();
                     break;
            case 2 : system("cls");
                     printf("--------Edit Inventory--------\n");
                     initial();
                     edit_task();
                   break;
            case 3 : system("cls");
                     printf("--------Delete Inventory--------\n");
                     initial();
                     deleteitem();
                   break;
            case 4 : listofallitems();
                   break;
            case 0 : exit(1);
                   break;
            default : 
                      system("cls");
                      printf("\nInvalid Input!\n\n\n");
                      system("PAUSE");
                      main();
                      break;
        }    
}


int initial()
{
       
    char line[30];                      
    numrec=0;
    x=0;
    int item;
    FILE *source=fopen("inventory.ini","rt");
    if (source==NULL)                        
    {
       printf("File missing...\n");
       system("PAUSE");
       exit(1);
    }

    while(!feof(source))                     
    {
       fscanf(source, "%[^\n]\n",line);
       numrec++;
    }
    fclose(source);
                          
    item=(source*)malloc(numrec*sizeof(source));
    FILE *src=fopen("inventory.ini","rt");
    while(!feof(src))
    {
       fscanf(source,"%[^\n]\n",line);    
       sscanf(line, "%s%c%s%c%f", item[x].code, &temp, item[x].desc, &temp, &item[x].price);    
       item[x].code[6]='\0'; 
         
       for (y=0;y<=10;y++)                        
       {
           if (item[x].desc[y]==',') item[x].desc[y]='\0'; 
       }
               
        x++;
    }
  fclose(src); 
}  

int add_itemcode()
{
   
    fflush(stdin);
       
    printf("Enter code [6 digits]            : ");
    gets(newcode);
    if (strcmp(newcode,"000")==0)
    {
        main();
    }
    else if (strlen(newcode)==6)
    {
       for (x=0;x<6;x++)   
       {
           if (newcode[x]!='0'&&newcode[x]!='1'&&newcode[x]!='2'&&newcode[x]!='3'&&newcode[x]!='4'&&newcode[x]!='5'&&newcode[x]!='6'&&newcode[x]!='7'&&newcode[x]!='8'&&newcode[x]!='9')
           {
              printf("\nItem code not valid...\n\n");
              add_itemcode();
           } 
        }

         for (x=0;x<numrec;x++)
         {
             if (strcmp(newcode,item[x].code)==0)
             {
                  printf("\nItem code already exists...\n\n");
                  add_itemcode();
              }
          }  
       }
       else
       {
            printf("\nItem code not valid...\n\n");
            add_itemcode();
        }
    
    add_itemdesc();
}


int add_itemdesc()
{
    printf("Enter item description [max 10 chars] : ");
    gets(newdesc);
    if (strcmp(newdesc,"000")==0)
    { 
       main();
    }
    else if (strlen(newdesc)>10)
    {
       printf("\nItem description not valid...\n\n");
       add_itemdesc();
    }
    else
    {

            if(strlen(newdesc)== 0)
            {
                printf("\nItem description not valid...\n\n");
                add_itemdesc();
            }
     }
    
    add_itemprice();
}


int add_itemprice() 
{
    printf("Enter unit price                 : ");
    gets(stemp);
    
    if (strcmp(stemp,"000")==0)
    {
        main();
    }
    
    for (x=0;x<strlen(stemp);x++)   
    {
        if (stemp[x]!='.'&&stemp[x]!='0'&&stemp[x]!='1'&&stemp[x]!='2'&&stemp[x]!='3'&&stemp[x]!='4'&&stemp[x]!='5'&&stemp[x]!='6'&&stemp[x]!='7'&&stemp[x]!='8'&&stemp[x]!='9')
        {
           printf("\nItem price not valid...\n\n");
           add_itemprice();
        } 
    }

    if(strlen(stemp)== 0)
    {
        printf("\nItem description not valid...\n\n");
        add_itemprice();
    }

    sscanf(stemp,"%f",&newprice);
    FILE *src=fopen("inventory.ini","at");
    fprintf(src,"\n%s, %s, %.2f",newcode,newdesc,newprice);
    fclose(src);
    printf("\n\nInventory item successfully added...\n\n\n");
    system("PAUSE");
    main();
}


int listofallitems() 
{
    initial();
    system("cls");
    printf("--------List All Inventories--------\n\n");
    printf("ITEM CODE       ITEM DESCRIPTION      ITEM PRICE\n\n");    

    for (x=0;x<numrec;x++)
    {
        if (strlen(item[x].desc) <= 7) //add another tab if item description is less than 7 characters : for fomatting only
        {
            printf("%s\t\t%s\t\t\t%.2f\n",item[x].code,item[x].desc,item[x].price);
        }
        else
        {
            printf("%s\t\t%s\t\t%.2f\n",item[x].code,item[x].desc,item[x].price);
        }
    }
    
    printf("\n");
    system("PAUSE");
    main();
}


int deleteitem() 
{
  printf("Enter code: ");
  gets(newcode);
  if (strcmp(newcode,"000")==0) main();
  if (strlen(newcode)==6)
  {
       for (x=0;x<6;x++)   
       {
           if (newcode[x]!='0'&&newcode[x]!='1'&&newcode[x]!='2'&&newcode[x]!='3'&&newcode[x]!='4'&&newcode[x]!='5'&&newcode[x]!='6'&&newcode[x]!='7'&&newcode[x]!='8'&&newcode[x]!='9')
           {
              printf("\nItem code not valid\n");
              deleteitem();
            } 
       }
       

       y=0;
       for (x=0;x<numrec;x++)
       {
           if (strcmp(newcode,item[x].code)==0)
           {
               y=1;
               break;
           }
       }
       

       if (y==0)
       {
           printf("\nItem code does not exist\n");
           deleteitem();
       } }
else
{
    printf("\n\t<<Invalid code!>>\n");
    deleteitem(); }
    printf("Description : %s\n", item[x].desc);
    printf("Unit price  : %.2f\n", item[x].price);
    printf("\nDelete current inventory entry? [y/n]: ");
    gets(stemp);
    if ((strcmp(stemp,"N")==0)||(strcmp(stemp,"n")==0))
    {
       printf("\nDeletion failed\n");
       system("PAUSE");
       main(); }
    else if ((strcmp(stemp,"Y")==0)||(strcmp(stemp,"y")==0))
    {
         item[x].erased=1;
         FILE *fpointer=fopen("inventory.ini","wt");
         for (x=0;x<numrec;x++)
         {
           if (item[x].erased!=1) fprintf(fpointer,"%s, %s, %.2f\n",item[x].code,item[x].desc,item[x].price);
         }
         fclose(fpointer);
         printf("\nItem deletion successful\n");
         system("PAUSE");
         main();}
    else
    {
       printf("\nInvalid input, delete failed...\n\n");
       system("PAUSE");
       main();
    }
}


int edit_task() 
{
    
    fflush(stdin); 
    printf("Enter code: ");
    gets(newcode);
    if (strcmp(newcode,"000")==0) main();
    else if (strlen(newcode)==6)
    {
      for (x=0;x<6;x++)   
       {
       if (newcode[x]!='0'&&newcode[x]!='1'&&newcode[x]!='2'&&newcode[x]!='3'&&newcode[x]!='4'&&newcode[x]!='5'&&newcode[x]!='6'&&newcode[x]!='7'&&newcode[x]!='8'&&newcode[x]!='9')
       {
         printf("\nCode not valid\n");
         edit_task();} }
       y=0;
      for (x=0;x<numrec;x++)
       {
       if (strcmp(newcode,item[x].code)==0)
           {
              y=1;
           break;} }
      if (y==0)
       {;
          printf("\nItem code does not exist\n");
          edit_task(); }}
    else
    {
        printf("\nCode not valid\n");
        edit_task(); 
    }
    printf("\n\n\nEnter new item\n" 
           "\tor Press enter key to accept current value...\n\n");
    edit_code();
}


int edit_code()
{
    
    fflush(stdin);

    printf("Enter code [%s]: ",item[x].code);
    gets(newcode);
    if (strcmp(newcode,"000")==0) main();
    else if (strlen(newcode)==0) 
    {
         strcpy(newcode,item[x].code);
         edit_desc();
    }
    else if (strlen(newcode)==6)
    {
      for (y=0;y<6;y++)   
       {
       if (newcode[y]!='0'&&newcode[y]!='1'&&newcode[y]!='2'&&newcode[y]!='3'&&newcode[y]!='4'&&newcode[y]!='5'&&newcode[y]!='6'&&newcode[y]!='7'&&newcode[y]!='8'&&newcode[y]!='9')
           {
              printf("\nCode not valid\n");
              edit_code(); } }
      for (y=0;y<numrec;y++)
       {
       if (strcmp(newcode,item[y].code)==0)
           {
              printf("\nDupulicate inventory code exists\n");
              edit_code(); } }
       edit_desc();}
    else
    {
        printf("\nCode not valid\n");
        edit_code(); }}


int edit_desc() 
{
    
    fflush(stdin);
    
    printf("Enter description [%s]: ",item[x].desc);
    gets(newdesc);
    if (strcmp(newdesc,"000")==0) main();
    else if (strlen(newdesc)==0) 
    {
         strcpy(newdesc,item[x].desc);
         edit_price();}
    else if (strlen(newdesc)>10)
    {

       printf("/nNot a valid item description\n");
       edit_desc();}
    else
    {
      for(y=0;y<strlen(newdesc);y++)
        {
        if(newdesc[y]==' ')
        {
    
            printf("\nNot a valid item description\n");
            edit_desc();}  } }
    edit_price();}

int edit_price() 
{
    
    fflush(stdin);
    
    printf("Enter unit price [%.2f]: ",item[x].price);
    gets(stemp);
    if (strcmp(stemp,"000")==0) main();
    else if (strlen(stemp)==0) newprice=item[x].price;
    else
    {
      for (y=0;y<strlen(stemp);y++)   
        {
      if (stemp[y]!='.'&&stemp[y]!='0'&&stemp[y]!='1'&&stemp[y]!='2'&&stemp[y]!='3'&&stemp[y]!='4'&&stemp[y]!='5'&&stemp[y]!='6'&&stemp[y]!='7'&&stemp[y]!='8'&&stemp[y]!='9')
      {
    
         printf("\nPrice not valid\n");
         edit_price (); }}
        sscanf(stemp,"%f",&newprice); }
        strcpy(item[x].code,newcode);
        strcpy(item[x].desc,newdesc);
        item[x].price=newprice;
        FILE *fpointer=fopen("inventory.ini","wt");
    for (x=0;x<numrec;x++)
    {
        fprintf(fpointer,"%s, %s, %.2f\n",item[x].code,item[x].desc,item[x].price); }
    fclose(fpointer);
    printf("\n\nInventory successfully edited.\n");
    system("PAUSE");
    main();}

The struct file (inventory.h) includes:

typedef struct 
{
    char code[6], temp;
    char desc[10];
    int qty;
    float price;
}INVINFO;
INVINFO *item;

The text file (inventory.ini) includes:

000001, hamburger, 30.50
000002, cheesburgr, 35.00
100001, frnchfries, 21.00
200001, icedtea, 17.00
100011, kowalaburgr, 22.50
200021, tigersteak, 65.25
300001, trtlnugets, 65.00

I'm getting a messed up errror about undeclared variables, I've been revamping each and every syntaxes and verified them but still no avail, can anyone clear this up for me? Thanks....

CAn you tell the exact line where the error is?

Oh sorry, major errors occur at line 89....

Oh sorry, major errors occur at line 89....

I would advise you to develop this program and get one function working first before moving onto the next function. Trying to write it all in one hit and then resolving all the errors is a laborious chore and an inefficient way of doing things.

From having a quick look at your code (sorry it's Saturday night) and I ain't gonna be looking at all that code, I've put forward some issues to be addressed:

1. The signature of main() is incorrect - at the very least make it int main(void).

2. Most of your functions return int, but I don't see a value being returned to the caller via the return statement.

3. At the end of some of those function you appear to be trying to call main() - you need to return <int-value> in these functions to get back to main() or any other caller function.

4. I see you are using gets function. Lose it - it is a dangerous function - use fgets instead.

5. fflush(stdin) is just plain wrong - drop it.

6. You reference the getch() function which is non-standard - and at any rate you haven't included the conio.h header file.

Well, that'll do for now. As I said earlier try to develop the program one "feature" at a time and get THAT right before moving on to the next function. This program has far more serious issues than undeclared variables - some of which I have pointed out above.

I have answered two other posts in recent times pertaining to this assignment (the inventory.ini file is a give away). Perhaps search for "inventory.ini" on the forum and read some of these posts.

Good luck!

Comments
I gotta give props for hitting the common noob stuff, since I haven't had the patience for that in a while.
This article has been dead for over six months. Start a new discussion instead.