have some errors, need some help

This is a discussion on have some errors, need some help within the C Programming forums, part of the General Programming Boards category; well this is just part of some code... granted its far from completetion and i have some comments to fill ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    9

    have some errors, need some help

    well this is just part of some code... granted its far from completetion and i have some comments to fill in some blanks but i need this portion of the code to work so i can continue with the rest of it... i was wondering if anyone would mind helping me out with these errors and warnings... im getting 7 errors and 6 warnings.... its kinda long so forgive me...

    Code:
    #include<stdio.h>
    #include<string.h>
    #include <ctype.h>
    
    	typedef struct
    	{
    	char brand[];
    	char bottles[];
    	int stock;
    	double price;
    	double cost;
    	}bev_t;
    
    void LoadFiveEntries(bev_t entries[], int *size);
    void Display(bev_t entries[], int *size);
    void Delete(bev_t entries[],int *size, int location);
    int find(bev_t entries[],int *size);
    
    
    int main()
    {
    	bev_t entries[150];
    	int size;
    	char selection;
    	size=0;
    		
    	
    	LoadFiveEntries(entries, &size);
    
    while(selection != 'Q' || 'q')
    {
    	if(selection == 'A' || 'a')
    	{
    		printf("Add\n");
    		//function for adding
    	}
    	else if(selection=='D' || 'd')
    	{
    		printf("Delete\n");
    		//function for deleting
    	}
    	else if(selection=='P' || 'p')
    	{
    		printf("Display\n");
    		Display(bev_t entries[], *size);
    	}
    	//continue with menu
    
    	else
    	{
    		printf("Command not recognized");
    	}
    
    	//prompt
    	//get next selection
    
    }
    //goodbye
    	return(0);
    }
    
    void LoadFiveEntries(bev_t entries[], int *size)
    {
    	entries[0].brand="Bud";
    	entries[0].stock=500;
    	//4 other entries
    	*size=*size+1;
    	return;
    }
    
    //continue to [4]
    
    void Display(bev_t entries[], int *size)
    {
    	int i;
    	for(i=0;i<size;i++)
    	{
    		printf("\n");
    		printf("Brand: \t%s\n", entries[i].brand);
    		printf("Bottles: \t%d\n", entries[i].bottles);
    		printf("Stock: \t%d\n", entries[i].stock);
    		printf("Price: \t%d\n", entries[i].price);
    		printf("Cost: \t%d\n", entries[i].cost);
    	}
    	return;
    }
    
    void Delete(bev_t entries[],int *size, int location)
    {
    	entries[location]=entries[*size-1];
    	*size=*size-1;
    	//delete array
    
    	return;
    }
    
    
    int find(bev_t entries[],int *size)
    {
    	int usersize,userBrand;
    	int i,j;
    	char tempBrand[20];
    	char userBrand[20];
    	usersize=strlen(userBrand);
    	printf("\nWhich brand would you like to see?\n");
    	scanf("%s",userBrand);
    	for(j=0;j<size;j++)
    	if(strcmp(userBrand,entries[j].brand)==0)
    		return(j);
    	else
    		return(-1);
    }

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    What are the errors you're getting? The first problem I see with just a glance is:
    Code:
    while(selection != 'Q' || 'q')
    || isn't quite that flexible. Try this instead:
    Code:
    while(selection != 'Q' || selection != 'q')
    Or, since you've already included ctype.h, use this:
    Code:
    while(toupper(selection) != 'Q')
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    9
    (8): error C2229: struct '__unnamed' has an illegal zero-sized array
    (9) : error C2229: struct '__unnamed' has an illegal zero-sized array
    (45) : error C2143: syntax error : missing ')' before 'type'
    (45) : error C2198: 'Display' : too few actual parameters
    (45) : error C2059: syntax error : ')'
    (64) : error C2106: '=' : left operand must be l-value
    (76) : warning C4047: '<' : 'int ' differs in levels of indirecti(on from 'int *'
    (103) : error C2040: 'userBrand' : 'char [20]' differs in levels of indirection from 'int '
    (104) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
    104) : warning C4024: 'strlen' : different types for formal and actual parameter 1
    (107) : warning C4047: '<' : 'int ' differs in levels of indirection from 'int *'
    (108) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
    (108) : warning C4024: 'strcmp' : different types for formal and actual parameter 1
    Error executing cl.exe.

    most of these i have no idea what their problem is... ='(

    btw... thanks for the earlier comment...

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,159
    Give your arrays in your struct a size (e.g. put a number between the [ and ]).

    Why are you trying to pass size as a pointer? There's no need to in this code. Also, the way you're calling Display() from your main() function is incorrect. You'll need to do a little function calling refresher.

    I'll leave the rest of the errors/warnings alone until you've got those solved.
    If you understand what you're doing, you're not learning anything.

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    9
    thanks all try to fix those for now

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    9
    ok well now im down to 2 errors... ive already made the structure and everything for bev_t entries but i get this error for this function...

    error C2106: '=' : left operand must be l-value

    for both the entries "BUD" and "BUDLIGHT"
    anybody know whats wrong?

    Code:
    void LoadFiveEntries(bev_t entries[], int *size)
    {
    	entries[0].brand="BUD";
    	entries[0].stock=500;
    	entries[0].bottles="BUDLIGHT";
    	entries[0].cost=1.50;
    	entries[0].price=1.75;
    
    	//4 other entries
    	*size=*size+1;
    	return;
    }

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    > entries[0].brand="BUD";
    strcpy( entries[0].brand, "BUD" );
    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.

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    9
    ah thx that helped

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 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 in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 05:51 PM

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