confusing error messages?

This is a discussion on confusing error messages? within the C Programming forums, part of the General Programming Boards category; this is for school and im getting a few error messages that are confusing me. really am clueless as to ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    255

    confusing error messages?

    this is for school and im getting a few error messages that are confusing me. really am clueless as to why they are occuring?


    Code:
    #include <stdlib.h>
    #include <string.h>
    #include <stdio.h>
    #include <conio.h>
    
    int get_int(char msg[]);
    double get_double(char msg[]);
    void display(char hauler[],double tot_trash[],int i);
    
    int main()
    {
    	char hauler[40][40];
    	char msg[200];
    	char end = ' ';
    	int trash = 0;
    	int l_trash;
    	int i = 0;
    	double tot_trash[40] = {0.0};
    	double rate;
    	double total = 0.0;
    	
    	while(end != 'Y')
    	{
    	printf("What is your name? %s\n",hauler);
    	gets(hauler[i]);
    	while(trash != 0)
    	{
    		strcpy(msg,"Enter how much trash you took out(0 to stop)? \n");
    		
    		trash = get_int(msg);
    		tot_trash[i] += trash;
    	}
    	strcpy(msg,"How Much trash did you dump last month? \n");
    
    	l_trash = get_int(msg);
    	if(trash < l_trash)
    		total = 350.00 * trash;
    	else
    	{	
    		strcpy(msg,"Enter the Tonnage Rate? \n");
    		rate = get_double(msg);
    		total = 350.00 * l_trash;
    		total += (350.00 + rate) * (trash - l_trash);
    	}
    	i++;
    	printf("Do you want to enter a new hauler(y or n)? %s\n",end);
    	end = getch();
    	end = toupper(end);
    	display(hauler[][],tot_trash[],i);
    return 0;
    }
    
    int get_int(char msg[])
    {
    	char buf[40];
    	printf(msg);
    	gets(buf);
    	return atoi(buf);;
    }
    
    double get_double(char msg[])
    {
    	char buf[40];
    	printf(msg);
    	gets(buf);
    	return atof(buf);
    }
    
    void display(char hauler[],double tot_trash[],int i)
    {
    	for(int j = 0;j<i;j++)
    	{
    		printf("Hauler: %s spent %d\n",hauler[j],tot_trash[j]);
    	}
    }
    c:\skool\Cpt235_1\proj 1\prog_1.cpp(53): error C2059: syntax error : ']'
    c:\skool\Cpt235_1\proj 1\prog_1.cpp(58): error C2601: 'get_int' : local function definitions are illegal
    c:\skool\Cpt235_1\proj 1\prog_1.cpp(66): error C2601: 'get_double' : local function definitions are illegal
    c:\skool\Cpt235_1\proj 1\prog_1.cpp(74): error C2601: 'display' : local function definitions are illegal
    c:\skool\Cpt235_1\proj 1\prog_1.cpp(80): fatal error C1075: end of file found before the left brace '{' at 'c:\skool\Cpt235_1\proj 1\prog_1.cpp(11)' was matched

    thanks
    hooch

  2. #2
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    You've confused yourself using strange indentation. You need a closing brace } to terminate your while after the display(hauler[][],tot_trash[],i); line and before return 0;

    Once you've fixed that, the other errors disappear, but some new ones occur. This is because you are incorrectly passing arrays (including two dimensional) to the functions.

    Have a read of http://c-faq.com/aryptr/index.html.
    Last edited by cwr; 01-26-2006 at 08:28 PM.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    c:\skool\Cpt235_1\proj 1\prog_1.cpp(46): error C3861: 'getch': identifier not found, even with argument-dependent lookup
    c:\skool\Cpt235_1\proj 1\prog_1.cpp(48): error C2664: 'display' : cannot convert parameter 1 from 'char [40][40]' to 'char []'


    well those are the two errors i get.

    so whyd you change

    display(hauler, tot_trash, i);

    that from what i had dont you need arrays to pass through?

    and the getch? dont i need the conio.h file???? at least thats what my book said anyway?
    hooch

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    or edit your post before i finished replying? lol
    hooch

  5. #5
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    I edited my post and removed my re-paste of your code, mainly because I didn't think it added much.

    I only removed conio.h because my system doesn't have it (or the getch function). You should include conio.h if you're going to use getch().

    Also, I changed display(hauler, tot_trash, i); just to get it to compile properly. You cannot pass an array like that. Whenever you pass an array to a function, you are just passing the address of the first element. In the case of a two dimensional array, the function must be declared such that the last dimension(s) are known. Example:
    Code:
    func(int a[][30]);
    
    int main(void)
    {
        int arr[30][30];
        func(arr); /* note: no [] here */
    }
    func(int a[][30]) /* 30 must be specified */
    {
        /* ... */
    }
    This is how the code generated in func knows what offsets to use when an array is passed.

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    well for school we have visual studio .net 2003 so it has it might go look up the other non microsoft way to do this later but for now this works.

    ok so i did this

    Code:
    display(hauler, tot_trash, i);//ERROR MESSAGE POINTS HERE
    void display(char hauler[][40], double tot_trash[], int i)
    {
        for(int j = 0; j < i; j++)
        {
            printf("Hauler: %s spent %d\n", hauler[j], tot_trash[j]);
        }
    }
    and got this error and unless i missed something that looks like what you just posted?

    c:\skool\Cpt235_1\proj 1\prog_1.cpp(49): error C2664: 'display' : cannot convert parameter 1 from 'char [40][40]' to 'char []'
    hooch

  7. #7
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    oops i forgot to change the function declartions at the top lol never mind it built fine now.
    hooch

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf is confusing me.
    By babelosopher in forum C Programming
    Replies: 10
    Last Post: 07-12-2007, 05:22 PM
  2. Most confusing language
    By Suchy in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 04-22-2007, 10:08 PM
  3. Arrays are confusing...
    By GavinHawk in forum C Programming
    Replies: 10
    Last Post: 11-29-2005, 01:09 AM
  4. pointers are confusing!
    By ali1 in forum C Programming
    Replies: 10
    Last Post: 09-07-2004, 11:41 PM
  5. functions declaration, pointers, cast, .... CONFUSING
    By Rhodium in forum C Programming
    Replies: 7
    Last Post: 01-09-2003, 06:21 AM

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