Thread: Too few arguments issue...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    8

    Question Too few arguments issue...

    Code:
    #include <stdio.h> #include <stdlib.h> #include <string.h> #define S 2 #define SS 4 typedef struct{ char ID[10], s_name[50]; double sales[1][SS]; }SALES_OF_SALESMAN; SALES_OF_SALESMAN D1[S]; typedef struct{ char gender[5], IC[11], date[20]; }SALESMAN_DETAILS; SALESMAN_DETAILS D2[S]; int mainmenu(void); int submenu(void); int AddSalesman(void); int QtrReport(void); int SalesComm(double total_s[N], int row, int col, double sales[S][SS], char s_name[S][50]); int main(void) { double total_s[S]={0}, total=0, average; int row=0, col=0, a=0; FILE * fptr, * fpt; fpt = fopen("Salesman.txt", "r"); fptr = fopen("Sales.txt", "w"); while(!feof(fpt)) { fscanf(fpt, "%[^|]|%[^|]|%[^|]|%[^|]|%[^\n]\n", &D1[row].ID, &D1[row].s_name, &D2[row].gender, &D2[row].IC, &D2[row].date); row++; } for(row=0; row < N; row++) { printf("Salesman's ID : %s\n", D1[row].ID); printf("Salesman's name : %s\n", D1[row].s_name); fprintf(fptr, "%s|", D1[row].ID); fflush(stdin); for(col=0; col < Q; col++) { printf("Salesman's quanterly sales : "); scanf("%lf", &D1[row].sales[0][col]); total_s[row] += D1[row].sales[0][col]; total += D1[row].sales[0][col]; fprintf(fptr, "%.2lf|", D1[row].sales[0][col]); } fprintf(fptr,"\n"); } average = total / S; mainmenu(); fclose(fpt); fclose(fptr); return 0; } int mainmenu(void) { int c1; printf("\n"); printf("Sales Processing System\n"); printf("-----------------------\n\n"); printf("1. Add Salesman Records\n2. Reports Generation\n3. Modify Salesman Records\n4.Delete Salesman Records\n\n0. Exit\n\n"); printf("Your choice: "); scanf("%d", &c1); while(c1!=0 && c1!=1 && c1!=2){ printf("Error! Please enter correctly! : "); scanf("%d", &c1); } if(c1==0) { printf("You are exiting this program...Bye bye.\n"); } else if (c1==1) { AddSalesman(); } else if(c1==2) { submenu(); } return 0; } int submenu(double total_s[S], int row, int col, double total, double average) { int c2; printf("\n"); printf("Report Generation\n"); printf("-----------------\n\n"); printf("1. View Quarterly Sales Report\n2. View Individual Salesman Commission\n\n0. Return to Main Menu\n\n"); printf("Your choice: "); scanf("%d", &c2); while(c2!=0 && c2!=1 && c2!=2){ printf("Error! Please enter correctly! : "); scanf("%d", &c2); } if(c2==0) { mainmenu(); } if(c2==1) { QtrReport(); } else if(c2==2) { SalesComm(total_s, row, col); } return 0; } int AddSalesman(void) { printf("addsalesman"); } int QtrReport(int row, int col, double total_s[S], double total, double average) { double hs; char hI[10]; for(row=0; row < N; row++) { printf("%-11s %-11s ", D1[row].ID, D1[row].s_name); for(col=0; col < 4; col++) { printf("%-11.2lf ", D1[row].sales[1][col]); } printf("%11.2lf\n", total_s[row]); } printf(" Total : %14.2lf\n", total); printf("Average sales : RM%.2lf\n", average); hs=total_s[0]; for(row = 0; row < N; row++) { for(col = 0; col < Q; col++) { if(total_s[row] > hs) { hs=total_s[row]; } } printf("Highest sales : RM%.2lf achieved by", hs); for(row = 0; row < N; row++) { if(hs==total_s[row]) { if(row==0) strcpy(hI, "S0001"); if(row==1) strcpy(hI, "S0002"); } } printf("\n"); } return 0; } int SalesComm(double total_s[S], int row, int col) { double commission; int s_ID; printf("1.%s %s\n2.%s %s", &D1[0].ID, &D1[0].s_name, &D1[1].ID, &D1[1].s_name); printf("Which Salesman do you want to view? Please enter his/her ID : "); scanf("%d", &s_ID); while(s_ID!=1 && s_ID!=2){ printf("Error! Please enter correctly! : "); scanf("%d", &s_ID); } if(s_ID==1) { row=0; } else if(s_ID==2) { row=1; } if(total_s[row]<50000) { commission = total_s[row]*0.03; } else if(total_s[row]<100000) { commission = total_s[row]*0.05; } else { commission = total_s[row]*0.08; } printf("Individual Salesman Commission for 2011\n"); printf("---------------------------------------\n\n"); printf("Salesman ID : %d", D1[row].ID); printf("Name : %s", D1[row].s_name); printf("Total Sales : %.2lf", total_s[row]); printf("Commission : %.2lf", commission); return 0; }
    'SalesComm' : too few arguments for call...how do I solve this error?

    And how can I solve the problem in int QtrReport()...I can't print out the result...
    Attached Files Attached Files
    Last edited by pp00; 11-13-2012 at 02:43 AM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Your declaration of SalesComm() specifies that it has 5 arguments.
    Code:
    int SalesComm(double total_s[N], int row, int col, double sales[S][SS], char s_name[S][50]);
    The definition (implementation) specifies that it has three arguments.
    Code:
    int SalesComm(double total_s[S], int row, int col)
    {
        /*   etc */
    and the call of SalesComm() supplies three
    Code:
         SalesComm(total_s, row, col);
    To stop the compiler rejecting your code (and complaining about too few or too many arguments to the call) the declaration, definition, and call of the function all need to involve exactly the same number of arguments. (and types need to be consistent too).

    The way you fix that is up to you. Options, depending on what you are trying to achieve, include;

    1) Correct the declaration so it specifies three arguments (of the same types as in the definition and the call of the function)

    2) Correct the function definition and the call point, so they involve five arguments (to align with the declaration)

    3) Correct the declaration, the function definition, and the call point so they all involve some other number of arguments (say 4).

    4) Delete the declaration, definition, and the line that calls SalesComm() completely from your code.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    8
    Thanks..

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    #1
    Code:
    while(!feof(fpt))
    Read: FAQ > Why it's bad to use feof() to control a loop

    #2
    Code:
    fflush(stdin);
    Read: FAQ > Why fflush(stdin) is wrong


    You look like you've got some other issues as well. Identifiers Q and N I see being used but don't see where they are declared. The posted code could use some formatting to make it easier to read. Your read loop increments a variable row but then immediately after that you have an output loop that sets row back to 0 when you really should be using a different looping variable that goes up until it reaches row instead (I think... you could be trying to do something I'm just not seeing). The aforementioned read loop does nothing to check that the array's index will be overrun before merrily going on about reading data (are you sure you will only ever have at most 2 entries in the input file?). You don't check to make sure your files are open. There may be others...
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bandwidth issue / network issue with wireless device communication
    By vlrk in forum Networking/Device Communication
    Replies: 0
    Last Post: 07-05-2010, 11:52 PM
  2. too many arguments
    By karfes in forum C Programming
    Replies: 3
    Last Post: 01-17-2009, 07:44 AM
  3. No Arguments
    By vb.bajpai in forum C Programming
    Replies: 3
    Last Post: 06-18-2007, 05:25 PM
  4. passing arguments using "Command Line Arguments"
    By Madshan in forum C++ Programming
    Replies: 1
    Last Post: 04-19-2006, 03:46 PM
  5. Int Arguments
    By Scytz0 in forum C++ Programming
    Replies: 6
    Last Post: 09-25-2003, 07:55 PM