Thread: Inventory System Help

  1. #1
    Registered User
    Join Date
    May 2019
    Posts
    2

    Inventory System Help

    My team and I are instructed to make a c programming regarding an inventory system but we bump on some errors and i dont understand the nature of this error. The text folder are already made so may i know on what to improvise. Thank you.

    warning: format '%d' expects argument of type 'int *', but argument has type 'int'

    undefined reference to fprintf


    Code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <conio.h>
    void record();
    void display();
    int ch;
    int no;
    int no2;
    int i;
    int c;
    int tools1,tools2,tools3;
    int day1,month1,year1;
    
    
    struct inventory
    {
            char fName1[50],fName2[50],lName1[50],lName2[50];
            int quantity1;
            int quantity2;
            int quantity3;
            int day1,month1,year1;
    }t1;
    
    
    int main()
    {
        tools1 = 10;
        tools2 = 10;
        tools3 = 10;
        do{
        do{
        printf("\t\t\tHello!\n\tWelcome to Laboratory Inventory System!\n\n");
        printf("Press number below according to the option below!\n");
        printf("\t1. Add Record\n\t2. Display Record\n\t3. Inventory Check\n");
        printf("Please enter your option?\n");
        switch(ch)
        {
            case 1:record();
            break;
    
    
            case 2:display();
            break;
    
    
            default: printf("\nInvalid Choice!\n");
            break;
        }
        }while(ch!=3);
        }while(tools1>0,tools2>0,tools3>0);
        system("cls");
        return 0;
    }
    void record()
    {
        FILE *fp;
        fp = fopen("LIBSUMP.txt", "w");
        for (i=0; i<no; i++)
        {
            printf("Please enter the first name of Person In Charge!(ex:Arif Imran).\n");
            scanf("%s %s",t1.fName1,t1.fName2);
            printf("Please enter the last name of Person In Charge!(ex:Ahmad Irfan).\n");
            scanf("%s %s",t1.lName1,t1.lName2);
            printf("Please enter the todays date!(ex:XX/YY/ZZZZ)\n");
            scanf("%d/%d/%d",&day1,&month1,&year1);
            int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
            int n = day1;
            t1.day1 = day1 +7;
            if (( month1 == 2 ) && (day1 == 29))
            {
                // Leap year checking, if yes, Feb is 29 days.
                if(year1 % 400 == 0 || (year1 % 100 != 0 && year1 % 4 == 0))
                {
                    daysInMonth[1] = 29;
                }
            }
    
    
            if (t1.day1 > daysInMonth[month1 -1])
            {
                t1.day1 = (t1.day1-*daysInMonth);
                t1.month1 = month1 +1;
                if (month1 > 12)
                {
                    t1.month1 = 1;
                    t1.year1 = year1 +1;
                }
            }
            printf("Please enter the amount of tools needed!\n");
            printf("\nProjector\t:");
            scanf("%d",t1.quantity1);
            tools1=tools1-t1.quantity1;
            printf("\nProjection Screen\t:");
            scanf("%d",t1.quantity2);
            tools2=tools2-t1.quantity2;
            printf("\nSound System\t:");
            scanf("%d",t1.quantity3);
            tools3=tools3-t1.quantity3;
            fprintf(fp,"PIC\t\t:%s %s %s %s",t1.fName1,t1.fName2,t1.lName1,t1.lName2);
            fprintf(fp,"Due date\t\t: %d/%d/%d",t1.day1,t1.month1,t1.year1);
            fpritnf(fp,"Projector\t\t: %d",t1.quantity1);
            fprintf(fp,"Projection Screen\t\t: %d",t1.quantity2);
            fprintf(fp,"Sound System\t\t: %d",t1.quantity3);
        }
        fclose(fp);
    }
    void display()
    {
        FILE *fp;
        fp=fopen("LIBSUMP.txt","r");
        while((c=getc(fp))!=EOF)
        {
            printf("%c",c);
        }
        fclose(fp);
        getch();
        system("cls");
    }
    main.c
    Last edited by Salem; 05-07-2019 at 10:42 PM. Reason: Added [code][/code] tags, learn to use them yourself

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,530
    > warning: format '%d' expects argument of type 'int *', but argument has type 'int'
    That's because you forgot an & on one of the parameters to one of your scanf calls.

    > undefined reference to fprintf
    That's not your error message. You wrote what you thought it should be, not what it is.

    Look carefully at line 102 and check your spelling.
    > fpritnf(fp,"Projector\t\t: %d",t1.quantity1);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2019
    Posts
    2
    Scratch above idea. My newbie group decided to follow this guy idea YouTube.
    Somehow we can't display back any data that i have inserted. Maybe due to lacking knowledge on the Array department. Any advice? Thank you in advance!.

    insert
    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<conio.h>
    #define true 0
    #define false 1
    
    
    int day1,month1,year1,day2,month2,year2;
    
    
    struct tools
        {
            char id[10];
            char PIC[20];
            int quantity1,quantity2,quantity3;
            int day1,month1,year1;
        };
        struct tools tool[30];
        int count = 0;
        FILE *f;
    
    
    int writefile()
    {
        int i;
        f = fopen("Inventory.text","w");
        if (f==NULL)
            return -1;
        fprintf(f, "%d\n",count);
        for (i=0;i<count;++i)
        {
            fputs(tool[i].id, f);
            fprintf(f, "\n");
            fputs(tool[i].PIC, f);
            fprintf(f, "\n");
            fprintf(f, "%d\n",tool[i].quantity1);
            fprintf(f, "%d\n",tool[i].quantity2);
            fprintf(f, "%d\n",tool[i].quantity3);
            fprintf(f, "%d\n",tool[i].day1);
            fprintf(f, "%d\n",tool[i].month1);
            fprintf(f, "%d\n",tool[i].year1);
        }
        fclose(f);
        return 0;
    }
    int readFile()
    {
        int n=0;
        int i;
        f=fopen("Inventory.txt", "r");
        if (f==NULL)
            return -1;
        fscanf(f, "%d\n", &n);
        for (i=0;i<n;++i)
        {
            fgets(tool[i].id, 10, f);
            tool[i].id[strlen(tool[i].PIC)-1]=0;
            fgets(tool[i].PIC, 20, f);
            tool[i].id[strlen(tool[i].PIC)-1]=0;
            fscanf(f, "%d", &tool[i].quantity1);
            fscanf(f, "%d", &tool[i].quantity2);
            fscanf(f, "%d", &tool[i].quantity3);
            fscanf(f, "%d", &tool[i].day1);
            fscanf(f, "%d", &tool[i].month1);
            fscanf(f, "%d", &tool[i].year1);
        }
        fclose(f);
        return n;
    }
    void addrecord()
    {
        printf("Enter The Ticket Number\n");
        readFile();
        if(count>0)
        {
            count=readFile();
            IDChecker(0,count);
        }
        else
        {
            printf("\nTicket Number:");
            fflush(stdin);
            gets(tool[count].id);
        }
        printf("Person In Charge: ");gets(tool[count].PIC);
        printf("Projector\t: ");scanf("%d", &tool[count].quantity1);
        printf("White Screen\t: ");scanf("%d", &tool[count].quantity2);
        printf("Audio System\t: ");scanf("%d", &tool[count].quantity3);
        printf("Enter Today's Date (ex:XX/YY/ZZZZ):");
        scanf("%d/%d/%d", &day1,&month1,&year1);
        int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int n = day1;
        day2 = day1 +7;
        if (( month1 == 2 ) && (day1 == 29))
        {
            // Leap year checking, if yes, Feb is 29 days.
            if(year1 % 400 == 0 || (year1 % 100 != 0 && year1 % 4 == 0))
            {
                daysInMonth[1] = 29;
            }
        }
    
    
        if (day2 > daysInMonth[month1 -1])
        {
            day2 = (day2-*daysInMonth);
            month2 = month1 +1;
            if (month1 > 12)
            {
                month2 = 1;
                year2 = year1 +1;
            }
        }
        tool[count].day1=day2;
        tool[count].month1=month2;
        tool[count].year1=year2;
        ++count;
        writefile();
    }
    void deleterecord()
    {
        count=readFile();
        char id[10];
        int i,j;
        int z=false;
        printf("Enter the Ticket Number thats been returned:");
        fflush(stdin);
        gets(id);
        for(i=0;i<count;i++)
        {
            z=true;
            if (strcmp(tool[i].id,id)==0)
            {
                for(j=i;j<(count-1);j++)
                {
                    tool[j]=tool[j+1];
                }
                count--;
            }
        }
        if (z==false)
        {
            printf("Can't ticket number:%s.",id);
        }
        writefile();
    }
    void displayrecord()
    {
        int i;
        count = readFile();
        if (count<0)
            puts("cannot open file");
        printf("\t\t\t wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n");
        printf("\t\t\t        Laboratory Inventory System\n");
        printf("\t\t\t wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n");
        printf("----------------------------------------------------------------\n");
        printf("|No.| Person In Charge | Ticket ID | Projector | White Screen | Audio System | Due Date|\n");
        printf("----------------------------------------------------------------\n");
        for(i=0;i<count;i++)
        {
            printf("%d %s %s %d %d %d %d %d %d",i+1,tool[i].PIC,tool[i].id,tool[i].quantity1,tool[i].quantity2,tool[i].quantity3,tool[i].day1,tool[i].month1,tool[i].year1);
        }
    }
    int IDChecker(int i,int j)
    {
        count=readFile();
        printf("Product ID:");
        fflush(stdin);
        gets(tool[count].id);
        if (strcmp(tool[i].id,tool[j].id)==0)
        {
            printf("ID Number is already taken!");
            return IDChecker(i++,j--);
        }
    }
    int checkID(char id[])
    {
        int i;
        count=readFile();
        readFile();
        for(i=0;i<count;i++)
        {
            if(strcmp(id,tool[i].id)!=0)
            {
                fclose(f);
            }
            return 1;
        }
        fclose(f);
        return 0;
    }
    int main()
    {
        int choice;
        count=readFile();
        if (count<0)
            printf("Cannot locate file\n");
    do  {
        printf("\n");
        printf("\t\t\t wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n");
        printf("\t\t\t   Welcome To Laboratory Inventory System\n");
        printf("\t\t\t wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n");
        printf("\n\nPress:");
        printf("\n\t1.)Add Record.");
        printf("\n\t2.)Delete Record.");
        printf("\n\t3.)Display Record.");
        printf("\n\t4.)Exit the program.");
        printf("\n\tChoice?\n");
        scanf("%d", &choice);
        switch(choice)
        {
            case 1: addrecord();
            break;
    
    
            case 2: deleterecord();
            break;
    
    
            case 3: displayrecord();
            break;
    
    
            case 4: exit(1);
            break;
    
    
            default: printf("Invalid Choices. Please try again.");
            break;
        }
    }while(choice!=4);
    printf("Thank You for using this program");
    }

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,235
    Quote Originally Posted by Brother5147
    My newbie group decided to follow this guy idea YouTube.
    Not a bad idea to look at the fellow's user interface for inspiration, but the code is awful.

    Before getting down to fixing what you want to fix, my advice:
    • Do not declare any global variables. If you're a good programmer, for such a trivial program it might not matter, but you're not yet a good programmer, so you should restrict yourself to local variables for practice. Global state makes it more difficult to reason about your program, hence making it more difficult to both write correct programs and maintain them.
    • Since you will not be declaring global variables, it means that your functions will have relevant parameters and return relevant values. This can help you think more clearly about what your functions should do. Break down large functions into smaller ones that each does one thing and does it well, e.g., write a helper function for leap year checking.
    • Never ever use the gets function as it is inherently vulnerable to buffer overflow. If your teacher requires you to use it, request to test your teacher's model answer program: you can crash it then laugh at your teacher for being a bad programmer. Instead of gets, use fgets, but note that fgets stores the newline from reading the line of input if there is space for it.
    • Avoid fflush(stdin) because it is non-standard. Careful application of a loop to read and discard characters until a newline or EOF is reached will usually suffice.
    • Note that <conio.h> is non-standard. I have not checked if you actually use it.
    • Do more error checking, e.g., check the return value of scanf, fscanf, and your own readFile function. Note that you can combine consecutive known fscanf calls into one by having a more comprehensive format string.
    • Your indentation could be improved to be more consistent.
    • Your naming could be more consistent too: writefile versus readFile. Either go with writeFile and readFile, or with writefile and readfile. I would suggest the former, or if you would like to keep them lowercase: write_file and read_file.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,530
    Unfortunately, the guy you chose to follow spent 20 minutes posting a pile of crap.

    > fflush(stdin);
    No, fflush() is for output streams, and update streams following a write.

    > gets(tool[count].id);
    No, no, no, absolutely NOT!
    Never use this function, it's dangerous and obsolete.

    > fgets(tool[i].PIC, 20, f);
    > tool[i].id[strlen(tool[i].PIC)-1]=0;
    > fscanf(f, "%d", &tool[i].quantity1);
    Mixing fgets() and fscanf() will cause you problems.
    fscanf doesn't care, but fgets() will trip up on the \n characters that previous fscanf calls leave behind.

    Code:
        readFile();
        if(count>0)
        {
            count=readFile();
            IDChecker(0,count);
    Seriously, how many times is it necessary to call readFile()?

    Code:
    int IDChecker(int i,int j)
    {
        count=readFile();
        printf("Product ID:");
        fflush(stdin);
        gets(tool[count].id);
        if (strcmp(tool[i].id,tool[j].id)==0)
        {
            printf("ID Number is already taken!");
            return IDChecker(i++,j--);
        }
    }
    Using recursion to implement a simple loop is an awful way to go.
    Also, when it does succeed, the function returns garbage anyway (no explicit return statement).

    Then there is the whole mess of poorly named global variables.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Book Inventory System
    By Tyler Small in forum C++ Programming
    Replies: 6
    Last Post: 11-12-2015, 09:49 PM
  2. problems with inventory system
    By a29bbas in forum C Programming
    Replies: 2
    Last Post: 01-07-2014, 11:50 AM
  3. Need help on Electronic Inventory System...
    By beh007 in forum C Programming
    Replies: 1
    Last Post: 12-27-2011, 08:42 PM
  4. Inventory System
    By headshot119 in forum C Programming
    Replies: 28
    Last Post: 09-24-2009, 10:53 AM
  5. inventory system
    By linucksrox in forum Game Programming
    Replies: 0
    Last Post: 04-19-2006, 01:19 PM

Tags for this Thread