Can't fix errors

This is a discussion on Can't fix errors within the C Programming forums, part of the General Programming Boards category; Hey all, this is probably something everyone will spot straight away but i've started writing my code and get some ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    19

    Can't fix errors

    Hey all, this is probably something everyone will spot straight away but i've started writing my code and get some errors I can't get past...

    error C2198: 'f_menu' : too few arguments for call
    error C2198: 'f_display' : too few arguments for call

    Heres my code
    Code:
    #include <stdio.h> 
    #include <stdlib.h>
    
    typedef struct 
    {
    	char id[5];
    	char first_name[20];
    	char surname[20];
    	int mem_type[5];
    	int expiry[5];
    } DATABASE;
    
    int f_menu (DATABASE);
    DATABASE f_add();
    void f_display(DATABASE);
    
    
    void main()
    {
    	DATABASE members;
    
    	int menu = 0;
    
    	menu = f_menu ();
    
    	do
    	{
    
    	switch (menu)
    	{
    	case 1 :
    		f_add ();
    		break;
    	case 2 :
    		f_display ();
    		break;
    	case 3 :
    		printf("Exiting Program\n\n");
    		break;
    	}
    } while (menu != 3);
    
    }
    
    int f_menu ()
    {
    	int menu = 0;
    
    	printf("\n\nLeisure Center Menu\n");
    	printf("  1. Add Members\n  2. Display Members\n  3. Exit\n ");
    	printf("\nEnter choice: ");
    
    	do
    	{
    		scanf("%d", &menu);
    		fflush(stdin);
    
    		if((menu < 1 ) || (menu > menu))
    		{
    			printf("Invalid choice. Try again: ");
    		}
    
    	} while ((menu < 1 ) || (menu > menu));
    
    	return (menu);
    }
    
    DATABASE f_add()
    {
    	DATABASE members;
    
    	printf("Enter member ID : ");
    	gets(members.id);
    
    	printf("Enter first name : ");
    	gets(members.first_name);
    
    	printf("Enter surname : ");
    	gets(members.surname);
    
    	printf("Enter membership type : ");
    	scanf(members.mem_type);
    	fflush(stdin);
    
    	printf("Enter memership expiry month (1-12) : ");
    	scanf(members.expiry);
    	fflush(stdin);
    
    	return members;
    }
    
    void f_display(DATABASE members)
    {
    
    }
    I'm a begginner as i'm sure you can all tell... so please keep it simple

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,406
    Code:
    menu = f_menu ();
    you have not put any argument in the function call, but you declare the function as having DATABASE struct as an argument

    Code:
    int f_menu (DATABASE);
    so you need to pass the struct in the call

    same goes for f_display

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    Another problem is that your function definitions really do take no arguments at all. You need to make up your mind: should they take arguments or should they not?
    After that, you have a lot more stuff to fix:
    SourceForge.net: Do not remove parameter names - cpwiki
    SourceForge.net: Gets - cpwiki
    SourceForge.net: Fflush - cpwiki
    You have also gotten the scanf wrong. It must take a string with a formatting that tells it how to to read the data. And you are also only passed along a variable to store the data. And you are also passing along integer arrays. I am thinking you might want to store the data inside ONE element inside the arrays, not the entire arrays.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    19
    I did what you guys said and it didnt change anything, I get the same errors...

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    So, what is your current code?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    19
    I been playing around with passing the struct in the function calls, but nothing I do fixes the errors, just makes more...

    Code:
    #include <stdio.h> 
    #include <stdlib.h>
    
    typedef struct 
    {
    	char id[5];
    	char first_name[20];
    	char surname[20];
    	int mem_type[5];
    	int expiry[5];
    } DATABASE;
    
    int f_menu (DATABASE);
    DATABASE f_add(DATABASE);
    void f_display(DATABASE);
    
    void main()
    {
    	
    	DATABASE members;
    
    	int menu = 0;
    
    	menu = f_menu (DATABASE);
    
    	do
    	{
    
    	switch (menu)
    	{
    	case 1 :
    		f_add (DATABASE members);
    		break;
    	case 2 :
    		f_display ();
    		break;
    	case 3 :
    		printf("Exiting Program\n\n");
    		break;
    	}
    } while (menu != 3);
    
    }
    
    int f_menu (DATABASE)
    {
    	int menu = 0;
    
    	printf("\n\nLeisure Center Menu\n");
    	printf("  1. Add Members\n  2. Display Members\n  3. Exit\n ");
    	printf("\nEnter choice: ");
    
    	do
    	{
    		scanf("%d", &menu);
    		fflush(stdin);
    
    		if((menu < 1 ) || (menu > menu))
    		{
    			printf("Invalid choice. Try again: ");
    		}
    
    	} while ((menu < 1 ) || (menu > menu));
    
    	return (menu);
    }
    
    DATABASE f_add(DATABASE)
    {
    	printf("Enter member ID : ");
    	gets(members.id);
    
    	printf("Enter first name : ");
    	gets(members.first_name);
    
    	printf("Enter surname : ");
    	gets(members.surname);
    
    	printf("Enter membership type : ");
    	scanf(members.mem_type);
    	fflush(stdin);
    
    	printf("Enter memership expiry month (1-12) : ");
    	scanf(members.expiry);
    	fflush(stdin);
    
    	return members;
    }
    
    void f_display(DATABASE)
    {
    
    }
    Last edited by renvaar; 01-12-2010 at 04:29 AM.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Let me take a peek at it. Back in a bit.

  8. #8
    Registered User
    Join Date
    Nov 2009
    Posts
    19
    I took it all out and put it all back in and got this with 2 different errors but fixed the previous ones...

    Code:
    #include <stdio.h> 
    #include <stdlib.h>
    
    typedef struct 
    {
    	char id[5];
    	char first_name[20];
    	char surname[20];
    	int mem_type[5];
    	int expiry[5];
    } DATABASE;
    
    int f_menu ();
    DATABASE f_add();
    void f_display();
    
    void main()
    {
    	
    	DATABASE members;
    
    	int menu = 0;
    
    	menu = f_menu ();
    
    	do
    	{
    
    	switch (menu)
    	{
    	case 1 :
    		f_add (DATABASE members);
    		break;
    	case 2 :
    		f_display ();
    		break;
    	case 3 :
    		printf("Exiting Program\n\n");
    		break;
    	}
    } while (menu != 3);
    
    }
    
    int f_menu ()
    {
    	int menu = 0;
    
    	printf("\n\nLeisure Center Menu\n");
    	printf("  1. Add Members\n  2. Display Members\n  3. Exit\n ");
    	printf("\nEnter choice: ");
    
    	do
    	{
    		scanf("%d", &menu);
    		fflush(stdin);
    
    		if((menu < 1 ) || (menu > menu))
    		{
    			printf("Invalid choice. Try again: ");
    		}
    
    	} while ((menu < 1 ) || (menu > menu));
    
    	return (menu);
    }
    
    DATABASE f_add( DATABASE members)
    {
    	printf("Enter member ID : ");
    	gets(members.id);
    
    	printf("Enter first name : ");
    	gets(members.first_name);
    
    	printf("Enter surname : ");
    	gets(members.surname);
    
    	printf("Enter membership type : ");
    	scanf(members.mem_type);
    	fflush(stdin);
    
    	printf("Enter memership expiry month (1-12) : ");
    	scanf(members.expiry);
    	fflush(stdin);
    
    	return members;
    }
    
    void f_display()
    {
    
    }
    now I get:
    error C2143: syntax error : missing ')' before 'type'
    error C2059: syntax error : ')'

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,411
    You have yet to fix what was pointed out to you.
    Furthermore, the problem is not any type of logic, but rather syntax. You have a book nearby? You should look at function call syntax, or failing the having a book, look at a tutorial.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You're going about making this program, the wrong way.

    What you want to do is start with the essential thing - your struct, and get it set up. Will one struct be enough to hold several members data?

    No. So you need an array of these structs. Get that first.

    Then start with ONE function, and get it working, then add another function, and get it working, etc.

    Big mistake to start on several functions, get a lot of code done, and then find out OOPS! 90% of it is not right, and has to be thrown out, and re-done.

    Here's your program with several suggestions in it. No, it does not work, these are suggestions to get rid of obvious errors, only.

    Code:
    #include <stdio.h> 
    #include <stdlib.h>
    
    typedef struct 
    {
    	char id[5];
    	char first_name[20];
    	char surname[20];
    	int mem_type[5];
    	int expiry[5];
    } DATABASE;
    
    int f_menu (void);
    //DATABASE f_add(DATABASE);
    void f_add(DATABASE members);
    void f_display(DATABASE);
    
    //void main()   //int main and with a return, please
    int main()
    {
    	
    	DATABASE members;
    
    	int menu = 0;
    
    	//menu = f_menu (DATABASE);
      //DATABASE is an alias for a struct, only.
      menu = f_menu();
    
    	do
    	{
    
    	switch (menu)
    	{
    	case 1 :
    		f_add (members);
    		break;
    	case 2 :
    		f_display (members);
    		break;
    	case 3 :
    		printf("Exiting Program\n\n");
    		break;
    	}
    } while (menu != 3);
    
      menu = getchar();
      return 0;
    }
    
    //int f_menu (DATABASE members) You don't need members in f_menu, at all.
    int f_menu()
    {
    	int menu = 0;
    
    	printf("\n\nLeisure Center Menu\n");
    	printf("  1. Add Members\n  2. Display Members\n  3. Exit\n ");
    	printf("\nEnter choice: ");
    
    	do
    	{
    		scanf("%d", &menu);
    		//fflush(stdin); <==NO! 
        /* You can't flush your kitchen sink, just your toilet */
    
    		if((menu < 1 ) || (menu > menu))
    		{
    			printf("Invalid choice. Try again: ");
    		}
    
    	} while ((menu < 1 ) || (menu > menu));
    
    	return (menu);
    }
    
    //DATABASE f_add(DATABASE)
    /*DATABASE is just an alias for a struct name. It's not "something"
      to be passed to any function. You want "members", instead.
    */
    void f_add(DATABASE members)
    {
    	printf("Enter member ID : ");
    	gets(members.id);
    
    	printf("Enter first name : ");
    	gets(members.first_name);
    
    	printf("Enter surname : ");
    	gets(members.surname);
    
    	printf("Enter membership type : ");
    
      //NOW c'mon! :)
    //	scanf(members.mem_type);
    //	fflush(stdin); //quit trying to flush the kitchen sink!
    
    	printf("Enter memership expiry month (1-12) : ");
    
      //Again!
    //	scanf(members.expiry);
    //	fflush(stdin);
      //no return needed
    }
    
    void f_display(DATABASE members)
    {
    
    }
    Why don't you start with adding a very small members[] of say 4, and put in three names, initially. Then in the functions that change the members data, you need to pass the address to the members array.

    The above gives no errors, but doesn't work either - it's just a step up.
    Last edited by Adak; 01-12-2010 at 05:10 AM.

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,418
    First, read this.
    A development process
    It's about not trying to write the whole thing in one go, then hoping the compiler will figure out what your 100+ line ramble actually means.

    Second, read the FAQ on why gets() is bad, and fflush(stdin) is a tool of the devil.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Strange/false errors
    By Ganoosh in forum Windows Programming
    Replies: 8
    Last Post: 10-20-2005, 04:54 PM
  3. strange errors?
    By egomaster69 in forum C Programming
    Replies: 6
    Last Post: 12-21-2004, 05:13 PM
  4. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 08:18 PM
  5. Errors when including winsock2.h
    By skiingwiz in forum Windows Programming
    Replies: 2
    Last Post: 12-27-2002, 06:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21