Like Tree8Likes
  • 4 Post By anduril462
  • 2 Post By javaeyes
  • 2 Post By ledow

help with automobile gallery assignment! i have 2 hours!

This is a discussion on help with automobile gallery assignment! i have 2 hours! within the C Programming forums, part of the General Programming Boards category; can somebody please help me with this assignment, i have only 2 hours left and i need someone with c ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    4

    help with automobile gallery assignment! i have 2 hours!

    can somebody please help me with this assignment, i have only 2 hours left and i need someone with c language expertise.


    this is my code, can anyone help me.

    CODE:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define SIZE 20
       
      struct car {
       char *Plate ;                           
       char *Brand;
       char *Model;
       char *Color;
       int ProductionYear;
       int Price;
       char *Status;
    };
    
    
      int  Adding_a_new_car(Car *galleryPtr);
      int  Update_the_information_of_the_selected_car(Car *galleryPtr);
      int  Renting_a_car(Car *galleryPtr);
      int  Taking_back_a_car(Car *galleryPtr);
      int  Searching_an_available_car(Car *galleryPtr);
      
    
    
    char* plate[SIZE] ={"TR1234A","TR4558A","TR7895A","TR7895A","TR1236A","TR1228A","TR2589A","TR2134A","TR2574A","TR4782A"}; 
    char* brand[SIZE] = {"Toyota","Toyota","Opel","Ferrari","Renault","Fiat","Ford","Opel","Fiat","Ford"}; 
    char* model[SIZE] = {"Verso","Anversis","Corsa","Anvensis","Clio","Vectra","Corsa","Corsa","Vectra","Corsa"}; 
    char* color[SIZE] = {"Green","Gray","Blue","Red","White","Blue","Red","Green","Gray","White"};
    int carYear[SIZE] = {"2004","2005","2002","2003","2005","2008","2009","2001","2004","2005"};
    int carPrice[SIZE] = {"60000","70000","30000","40000","70000","30000","60000","80000","10000","90000"};
    char* status[SIZE] = {"available","rented","available","available","rented","available","available","rented","rented","available"};
    
    
       
      typedef struct car Car;
     
    
    
        
    
    
    
    
    int main(int argc, char *argv[])
    {
        Car gallery[20]; 
        
        
         char plate[20];
         char brand[20];
         char model[20];
         char color[20]
         int productionyear;
         int price;
         char status[20];
    
    
        
        
         int selection = 0;
        
        while(selection != 5)
        {
            
        print_menu();  
        
        scanf("%d", &selection); 
        
             switch(selection)      
             {
               case 1:
                   Adding_a_new_car(gallery);
                   break;
               case 2:
                    Update_the_information_of_the_selected_car(gallery);
                    break;
               case 3:
                    Renting_a_car(gallery);
                    break;
               case 4:
                    Taking_back_a_car(gallery);
                    break;
               case 5:
                    Searching_an_available_car(gallery);                
                    break;
             }
        }
        
      system("PAUSE");    
      return 0;
    }
    
    
    int  Adding_a_new_car(gallery)
    {
       
       
    
    
         printf("\t%-10s%s", "Plate", ":");
         scanf("%s", plate);
        
         printf("\t%-10s%s","Brand", ":");
         scanf("%s", brand);
         
         printf("\t%-10s%s","Model", ":");
         scanf("%s", model);
           
         printf("\t%-10s%s","Color", ":");
         scanf("%s", color);
           
         printf("\t%-10s%s","Production Year", ":");
         scanf("%d", &carYear);
         
          printf("\t%-10s%s","Price", ":");
         scanf("%d", &carPrice);
         
         printf("\t%-10s%s","Status", ":");
         scanf("%s", status);
         
         
         gallery.Plate = plate;
         gallery.Brand = brand;
         gallery.Model = model;
         gallery.Color = color;
         gallery.ProductionYear = carYear;
         gallery.Price = carPrice;
         gallery.Status = status;
         
        printf("\n\n----| car Info |----\n\n");
       printf("%10s: %s\n","Plate", gallery.Plate);
       printf("%10s: %s\n", "Brand", gallery.Brand);
       printf("%10s: %d\n", "Model", gallery.Model);
       printf("%10s: %d\n", "Color", gallery.Color );
       printf("%10s: %s\n", "ProductionYear", gallery.ProductionYear);
       printf("%10s: %s\n","Price", gallery.Price);
       printf("%10s: %s\n","Status", gallery.Status);
             
             system("PAUSE");
         }
    
    
    
    
    int Update_the_information_of_the_selected_car(gallery)
    {
        
        int i;
         
        printf("enter the plate of the car : %s", plate);
        scanf("%s", &plate)
        
        for (i = 0; i<19 ; i++){
            
            result = strncmp( plate, plate[i], 20);
            
        if(result == 0)
         {
           printf("\t%-10s%s","enter the new brand", ":");
         scanf("%s", brand);
         
         printf("\t%-10s%s","enter the new model", ":");
         scanf("%d", model);
           
         printf("\t%-10s%s","enter the new color", ":");
         scanf("%d", color);
           
         printf("\t%-10s%s","enter the new production year", ":");
         scanf("%s", &carYear);
         
          printf("\t%-10s%s","enter the new price", ":");
         scanf("%d", &carPrice);
         
         printf("\t%-10s%s","enter the new status", ":");
         scanf("%d", status);
           
           
         Car.Brand = brand;
         Car.Model = model;
         Car.Color = color;
         Car.ProductionYear = carYear;
         Car.Price = carPrice;
         Car.Status = status;
         
         
          printf("\n\n----| car's new Info |----\n\n");
       printf("%10s: %s\n","Plate", Car.Plate);
       printf("%10s: %s\n", "Brand", Car.Brand);
       printf("%10s: %d\n", "Model", Car.Model);
       printf("%10s: %d\n", "Color", Car.Color );
       printf("%10s: %s\n", "ProductionYear", Car.ProductionYear);
       printf("%10s: %s\n","Price", Car.Price);
       printf("%10s: %s\n","Status", Car.Status);
           
         }
         
         else {
              printf("\n Sorry , the car with plate : %s has not been found\n\n",plate);
              }
        system ("PAUSE");
        }
        
    
    
    
    
    
    
    int Renting_a_car()
    {
        
        
         printf("enter the plate of the car : %s", plate);
        scanf("%s", plate)
        
        for (i = 0; i<9 ; i++){
            
            result = strncmp( plate, plate[i], 20);
            
        if(result == 0)
         {
             printf("\t%-10s%s","enter the new status", ":");
             scanf("%d", status);
             
             Car.Status = status;
             
              printf("%10s: %s\n","Status", Car.Status);
                  }
        else {
             printf ("\n sorry the plate %s u have entered is wrong.\n\n",plate);
             }
         system ("PAUSE");
        }
    
    
    
    
    int Taking_back_a_car()
    {
         printf("enter the plate of the car : %s", plate);
        scanf("%s", plate)
        
        for (i = 0; i<9 ; i++){
            
            result = strncmp( plate, plate[i], 20);
            
        if(result == 0)
         {
            printf("\t%-10s%s","enter the status \"available\" ", ":");
             scanf("%d", status);
             
              Car.Status = status;
             
              printf("%10s: %s\n","Status", Car.Status);
             }
                  
            else {
                  printf ("\n sorry the plate %s u have entered is wrong.\n\n",plate);
                 }      
        }
        
    int Searching_an_available_car()
    {
        
        }
    
    
    
    
    int print_menu()
    {
        system("CLS");
        printf("--- Car gallary management  ---\n\n");
        printf("\n%d.Adding a new car\n",1);
        
        printf("----------------\n");
         printf("\n%d.Updating the information of the selected car\n",2);
         printf("----------------\n");
        
         printf("\n%d.Renting a car \n",3);
         printf("----------------\n");
         
         printf("\n%d.Taking back a car \n",4);
         printf("----------------\n");
         
         printf("\n%d.Searching an available car \n",5);
         printf("----------------\n");
         
        printf("\n Your selection \n");
        
        return 0;
        
        
        }
    it wont compile at all.

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Code:
    scanf("%s", plate);
    You're overwriting the global array of plates. Why don't you just scanf() directly into the struct, and remember that you need to malloc() as well:

    Code:
    Car.plate = malloc(10);
    scanf("%10s", Car.plate);
    You need to develop a consistent system for passing arguments. Most likely, you should keep a local array of 20 cars in main, and then pass this to each of the functions, which will handle it appropriately. And, in the definitions, you need to specify what types the function accepts, right now it expects an int, even though the prototypes specified Car *.

    Code:
    int Update_the_information_of_the_selected_car(Car *gallery)
    Seriously? Do you have something against:
    Code:
    int update_car_info(Car *gallery)
    There's a lot of other errors too, I advise you to mentally follow the paths of the arguments you pass, and the variables you're using, because you'll see the many inconsistencies that cause the program to not work.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,469
    What error(s) do you get when you compile? Start with the first one and fix it. The compiler tries to carry on despite the error, so sometimes later errors disappear when you fix the first one.

  4. #4
    Registered User
    Join Date
    Mar 2012
    Posts
    4
    Quote Originally Posted by anduril462 View Post
    What error(s) do you get when you compile? Start with the first one and fix it. The compiler tries to carry on despite the error, so sometimes later errors disappear when you fix the first one.
    well i fixed a few syntax erros but this seems to be a logical error, however i cant seem to solve it and the deadline is in 1 hour (((((

    UPDATED CODE AFTER A FEW FIXES OF SYNTAX ERRORS
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define SIZE 20
       
      struct car {
       char *Plate ;                           
       char *Brand;
       char *Model;
       char *Color;
       int ProductionYear;
       int Price;
       char *Status;
    };
    
    
     typedef struct car Car;
      int  Adding_a_new_car(Car *galleryPtr);
      int  Update_the_information_of_the_selected_car(Car *galleryPtr);
      int  Renting_a_car(Car *galleryPtr);
      int  Taking_back_a_car(Car *galleryPtr);
      int  Searching_an_available_car(Car *galleryPtr);
      
    
    
    char* plate[SIZE] ={"TR1234A","TR4558A","TR7895A","TR7895A","TR1236A","TR1228A","TR2589A","TR2134A","TR2574A","TR4782A"}; 
    char* brand[SIZE] = {"Toyota","Toyota","Opel","Ferrari","Renault","Fiat","Ford","Opel","Fiat","Ford"}; 
    char* model[SIZE] = {"Verso","Anversis","Corsa","Anvensis","Clio","Vectra","Corsa","Corsa","Vectra","Corsa"}; 
    char* color[SIZE] = {"Green","Gray","Blue","Red","White","Blue","Red","Green","Gray","White"};
    int carYear[SIZE] = {2004,2005,2002,2003,2005,2008,2009,2001,2004,2005};
    int carPrice[SIZE] = {60000,70000,30000,40000,70000,30000,60000,80000,10000,90000};
    char* status[SIZE] = {"available","rented","available","available","rented","available","available","rented","rented","available"};
    
    
       
     
     
    
    
        
    
    
    
    
    int main(int argc, char *argv[])
    {
        Car gallery[20]; 
        
        
         char plate[20];
         char brand[20];
         char model[20];
         char color[20];
         int productionyear;
         int price;
         char status[20];
    
    
        
        
         int selection = 0;
        
        while(selection != 5)
        {
            
        print_menu();  
        
        scanf("%d", &selection); 
        
             switch(selection)      
             {
               case 1:
                   Adding_a_new_car(gallery);
                   break;
               case 2:
                    Update_the_information_of_the_selected_car(gallery);
                    break;
               case 3:
                    Renting_a_car(gallery);
                    break;
               case 4:
                    Taking_back_a_car(gallery);
                    break;
               case 5:
                    Searching_an_available_car(gallery);                
                    break;
             }
        }
        
      system("PAUSE");    
      return 0;
    }
    
    
    int  Adding_a_new_car(gallery)
    {
       
       
    
    
         printf("\t%-10s%s", "Plate", ":");
         scanf("%s", plate);
        
         printf("\t%-10s%s","Brand", ":");
         scanf("%s", brand);
         
         printf("\t%-10s%s","Model", ":");
         scanf("%s", model);
           
         printf("\t%-10s%s","Color", ":");
         scanf("%s", color);
           
         printf("\t%-10s%s","Production Year", ":");
         scanf("%d", &carYear);
         
          printf("\t%-10s%s","Price", ":");
         scanf("%d", &carPrice);
         
         printf("\t%-10s%s","Status", ":");
         scanf("%s", status);
         
         
         gallery.Plate = plate;
         gallery.Brand = brand;
         gallery.Model = model;
         gallery.Color = color;
         gallery.ProductionYear = carYear;
         gallery.Price = carPrice;
         gallery.Status = status;
         
        printf("\n\n----| car Info |----\n\n");
       printf("%10s: %s\n","Plate", gallery.Plate);
       printf("%10s: %s\n", "Brand", gallery.Brand);
       printf("%10s: %d\n", "Model", gallery.Model);
       printf("%10s: %d\n", "Color", gallery.Color );
       printf("%10s: %s\n", "ProductionYear", gallery.ProductionYear);
       printf("%10s: %s\n","Price", gallery.Price);
       printf("%10s: %s\n","Status", gallery.Status);
             
             system("PAUSE");
         }
    
    
    
    
    int Update_the_information_of_the_selected_car(gallery)
    {
        
        int i;
         
        printf("enter the plate of the car : %s", plate);
        scanf("%s", &plate);
        
        for (i = 0; i<19 ; i++){
            
            result = strncmp( plate, plate[i], 20);
            
        if(result == 0)
         {
           printf("\t%-10s%s","enter the new brand", ":");
         scanf("%s", brand);
         
         printf("\t%-10s%s","enter the new model", ":");
         scanf("%d", model);
           
         printf("\t%-10s%s","enter the new color", ":");
         scanf("%d", color);
           
         printf("\t%-10s%s","enter the new production year", ":");
         scanf("%s", &carYear);
         
          printf("\t%-10s%s","enter the new price", ":");
         scanf("%d", &carPrice);
         
         printf("\t%-10s%s","enter the new status", ":");
         scanf("%d", status);
           
           
         Car.Brand = brand;
         Car.Model = model;
         Car.Color = color;
         Car.ProductionYear = carYear;
         Car.Price = carPrice;
         Car.Status = status;
         
         
          printf("\n\n----| car's new Info |----\n\n");
       printf("%10s: %s\n","Plate", Car.Plate);
       printf("%10s: %s\n", "Brand", Car.Brand);
       printf("%10s: %d\n", "Model", Car.Model);
       printf("%10s: %d\n", "Color", Car.Color );
       printf("%10s: %s\n", "ProductionYear", Car.ProductionYear);
       printf("%10s: %s\n","Price", Car.Price);
       printf("%10s: %s\n","Status", Car.Status);
           
         }
         
         else {
              printf("\n Sorry , the car with plate : %s has not been found\n\n",plate);
              }
        system ("PAUSE");
        }
        
    
    
    
    
    
    
    int Renting_a_car()
    {
        
        
         printf("enter the plate of the car : %s", plate);
        scanf("%s", plate);
        
        for (i = 0; i<9 ; i++){
            
            result = strncmp( plate, plate[i], 20);
            
        if(result == 0)
         {
             printf("\t%-10s%s","enter the new status", ":");
             scanf("%d", status);
             
             Car.Status = status;
             
              printf("%10s: %s\n","Status", Car.Status);
                  }
        else {
             printf ("\n sorry the plate %s u have entered is wrong.\n\n",plate);
             }
         system ("PAUSE");
        }
    
    
    
    
    int Taking_back_a_car()
    {
         printf("enter the plate of the car : %s", plate);
        scanf("%s", plate);
        
        for (i = 0; i<9 ; i++){
            
            result = strncmp( plate, plate[i], 20);
            
        if(result == 0)
         {
            printf("\t%-10s%s","enter the status \"available\" ", ":");
             scanf("%d", status);
             
              Car.Status = status;
             
              printf("%10s: %s\n","Status", Car.Status);
             }
                  
            else {
                  printf ("\n sorry the plate %s u have entered is wrong.\n\n",plate);
                 }      
        }
        
    int Searching_an_available_car()
    {
        
        }
    
    
    
    
    int print_menu()
    {
        system("CLS");
        printf("--- Car gallary management  ---\n\n");
        printf("\n%d.Adding a new car\n",1);
        
        printf("----------------\n");
         printf("\n%d.Updating the information of the selected car\n",2);
         printf("----------------\n");
        
         printf("\n%d.Renting a car \n",3);
         printf("----------------\n");
         
         printf("\n%d.Taking back a car \n",4);
         printf("----------------\n");
         
         printf("\n%d.Searching an available car \n",5);
         printf("----------------\n");
         
        printf("\n Your selection \n");
        
        return 0;
        
        
        }

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    4
    error: request for member `Plate' in something not a structure or union is the next error i get

  6. #6
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    In your abominably named function "Adding_a_new_car", not only is the prototype different from the declaration, but you just made up a bunch of variables. When I told you to change the scanf() calls, I was telling you to remove the old and malformed ones, hoping you'd figure it out.

    Everything before
    Code:
    printf("\n\n----| car Info |----\n\n");
    should be deleted. And you still aren't allocating memory, so I hope wherever scanf() writes to is owned by you. (hint: it won't be, and it will crash).

    You have lots of unused variables in main, and it looks like you think declaring them in main will make them visible to all the other functions, which isn't true.

    Actually, because your compiler doesn't seem to be doing anything (or you aren't listening to it), here's what's wrong with your code:

    Code:
    main.c: In function ‘main’:
    main.c:65: warning: implicit declaration of function ‘print_menu’
    main.c:55: warning: unused variable ‘status’
    main.c:54: warning: unused variable ‘price’
    main.c:53: warning: unused variable ‘productionyear’
    main.c:52: warning: unused variable ‘color’
    main.c:51: warning: unused variable ‘model’
    main.c:50: warning: unused variable ‘brand’
    main.c:49: warning: unused variable ‘plate’
    main.c: In function ‘Adding_a_new_car’:
    main.c:95: error: argument ‘gallery’ doesn’t match prototype
    main.c:17: error: prototype declaration
    main.c:101: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:104: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:107: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:110: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:113: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int (*)[20]’
    main.c:116: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int (*)[20]’
    main.c:119: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:122: error: request for member ‘Plate’ in something not a structure or union
    main.c:123: error: request for member ‘Brand’ in something not a structure or union
    main.c:124: error: request for member ‘Model’ in something not a structure or union
    main.c:125: error: request for member ‘Color’ in something not a structure or union
    main.c:126: error: request for member ‘ProductionYear’ in something not a structure or union
    main.c:127: error: request for member ‘Price’ in something not a structure or union
    main.c:128: error: request for member ‘Status’ in something not a structure or union
    main.c:131: error: request for member ‘Plate’ in something not a structure or union
    main.c:132: error: request for member ‘Brand’ in something not a structure or union
    main.c:133: error: request for member ‘Model’ in something not a structure or union
    main.c:134: error: request for member ‘Color’ in something not a structure or union
    main.c:135: error: request for member ‘ProductionYear’ in something not a structure or union
    main.c:136: error: request for member ‘Price’ in something not a structure or union
    main.c:137: error: request for member ‘Status’ in something not a structure or union
    main.c:140: warning: control reaches end of non-void function
    main.c: In function ‘Update_the_information_of_the_selected_car’:
    main.c:146: error: argument ‘gallery’ doesn’t match prototype
    main.c:18: error: prototype declaration
    main.c:150: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:151: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char * (*)[20]’
    main.c:155: error: ‘result’ undeclared (first use in this function)
    main.c:155: error: (Each undeclared identifier is reported only once
    main.c:155: error: for each function it appears in.)
    main.c:155: warning: implicit declaration of function ‘strncmp’
    main.c:160: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:163: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘char **’
    main.c:166: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘char **’
    main.c:169: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int (*)[20]’
    main.c:172: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int (*)[20]’
    main.c:175: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘char **’
    main.c:178: error: expected identifier or ‘(’ before ‘.’ token
    main.c:178: warning: ISO C90 forbids mixed declarations and code
    main.c:179: error: expected identifier or ‘(’ before ‘.’ token
    main.c:180: error: expected identifier or ‘(’ before ‘.’ token
    main.c:181: error: expected identifier or ‘(’ before ‘.’ token
    main.c:182: error: expected identifier or ‘(’ before ‘.’ token
    main.c:183: error: expected identifier or ‘(’ before ‘.’ token
    main.c:187: error: expected expression before ‘Car’
    main.c:188: error: expected expression before ‘Car’
    main.c:189: error: expected expression before ‘Car’
    main.c:190: error: expected expression before ‘Car’
    main.c:191: error: expected expression before ‘Car’
    main.c:192: error: expected expression before ‘Car’
    main.c:193: error: expected expression before ‘Car’
    main.c:198: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:210: warning: ISO C forbids nested functions
    main.c: In function ‘Renting_a_car’:
    main.c:210: error: number of arguments doesn’t match prototype
    main.c:19: error: prototype declaration
    main.c:213: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:214: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:223: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘char **’
    main.c:225: error: expected identifier or ‘(’ before ‘.’ token
    main.c:225: warning: ISO C90 forbids mixed declarations and code
    main.c:227: error: expected expression before ‘Car’
    main.c:230: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:239: warning: ISO C forbids nested functions
    main.c: In function ‘Taking_back_a_car’:
    main.c:239: error: number of arguments doesn’t match prototype
    main.c:20: error: prototype declaration
    main.c:240: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:241: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:250: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘char **’
    main.c:252: error: expected identifier or ‘(’ before ‘.’ token
    main.c:252: warning: ISO C90 forbids mixed declarations and code
    main.c:254: error: expected expression before ‘Car’
    main.c:258: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char **’
    main.c:263: warning: ISO C forbids nested functions
    main.c: In function ‘Searching_an_available_car’:
    main.c:263: error: number of arguments doesn’t match prototype
    main.c:21: error: prototype declaration
    main.c: In function ‘Taking_back_a_car’:
    main.c:262: warning: ISO C90 forbids mixed declarations and code
    main.c:271: warning: ISO C forbids nested functions
    main.c:294: error: expected declaration or statement at end of input
    main.c: In function ‘Renting_a_car’:
    main.c:238: warning: ISO C90 forbids mixed declarations and code
    main.c:294: error: expected declaration or statement at end of input
    main.c: In function ‘Update_the_information_of_the_selected_car’:
    main.c:209: warning: ISO C90 forbids mixed declarations and code
    main.c:294: error: expected declaration or statement at end of input
    main.c: In function ‘Searching_an_available_car’:
    main.c:265: warning: control reaches end of non-void function
    main.c: In function ‘Taking_back_a_car’:
    main.c:294: warning: control reaches end of non-void function
    main.c: In function ‘Renting_a_car’:
    main.c:294: warning: control reaches end of non-void function
    main.c: In function ‘Update_the_information_of_the_selected_car’:
    main.c:294: warning: control reaches end of non-void function

  7. #7
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    You're not listening to the advice you're given.

    Memcpy already told you that you don't do this:
    Code:
             scanf("%s", plate);
    when "plate" is an array of strings. You're over-writing the entire array of strings, rather than just storing one of the strings. Many of your other errors are similar in nature; you're trying to scan in something that's a different type to the variable you want to hold it in.

    There are two steps you need to follow to fix your code.
    1) Pay attention to what the compiler tells you, and act on that advice.
    2) Pay attention to what the forum members tell you, and act on that advice.
    Code:
    while(!asleep) {
       sheep++;
    }

  8. #8
    Registered User
    Join Date
    Mar 2012
    Posts
    4
    am using devc++ what compiler are you guys using?

  9. #9
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,469
    I'm using GCC, can't speak for the others. Dev-C++ is outdated and unmaintained, but it should still warn you about much of this if you turn up the warnings (sorry, don't use it, so I can't help you with how to do that). Pelles C is a user-friendly alternative for Windows, or you could use Code::Blocks with MinGW. But that's for after you turn in this program.

    In your function definitions, you need to have a type for each parameter like you do in your prototypes. Otherwise, I think the compiler assumes they're an int.
    Code:
    int add_car(Car *gallery)
    {
        scanf("%s", gallery->Plate);
        ...
    }
    Notice I also used -> instead of . If you have a pointer to a struct, you use -> to access the members, . is for when you have an actual struct. Fixing those issues everywhere in your code should clear up a lot of your issues.

    You need to allocate memory for each thing you scan into, as memcpy pointed out. The easy way to make sure you have memory for storing this stuff is to just make the struct use char arrays instead of char pointers:
    Code:
    struct car {
        char Plate[20];  // or whatever a sufficient length is
        ...
    };
    Good luck, though to be honest, I doubt you'll have anything close to working by the time your deadline hits. But I suppose that's fair enough, considering it looks like you threw together 300 lines of crap at the last minute, with no planning or testing. Maybe the bad grade will be a lesson for you.
    memcpy, TheBigH, Salem and 1 others like this.

  10. #10
    Registered User javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153
    You really can't just barf out a ton of code and expect anything to compile or function correctly. Start over. Write a small program, 5 to 10 lines of code, that does just 1 feature you want to add. get it to compile. Do a little testing. Repeat.
    Salem and phantomotap like this.

  11. #11
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    I love the way everyone else's deadlines somehow become "our" deadlines because of their inability to properly set aside time for the work they are given.

    I'm also beginning to love people who don't figure out that warnings are not there to be ignored any more than a road sign that says "Warning: Slow down. Sharp curve ahead". Sure, you may be going slow enough anyway, but if you're on a road you don't know, it's probably best to heed the notice and do something about it (i.e. slow down / fix the problem) before you get there. -Wall -Werror should be compulsory and you should have to override warnings yourself in those circumstances that you know what you're doing, and then the compiler should print them in BIG RED LETTERS anyway.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  12. #12
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by ledow View Post
    I love the way everyone else's deadlines somehow become "our" deadlines because of their inability to properly set aside time for the work they are given.

    I'm also beginning to love people who don't figure out that warnings are not there to be ignored any more than a road sign that says "Warning: Slow down. Sharp curve ahead". Sure, you may be going slow enough anyway, but if you're on a road you don't know, it's probably best to heed the notice and do something about it (i.e. slow down / fix the problem) before you get there. -Wall -Werror should be compulsory and you should have to override warnings yourself in those circumstances that you know what you're doing, and then the compiler should print them in BIG RED LETTERS anyway.
    Yes, the typical attitude towards warnings is: "I don't have time for this crap, I have tons of ERRORS to fix first".
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    2 hour deadline has long since past.
    All that was useful to say has been said.
    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. automobile program
    By gunghomiller in forum C++ Programming
    Replies: 16
    Last Post: 08-08-2007, 09:29 PM
  2. One now owns an automobile!
    By cboard_member in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 04-22-2007, 05:34 PM
  3. Javascript Gallery Help
    By Flakster in forum Tech Board
    Replies: 5
    Last Post: 07-21-2005, 04:50 AM
  4. ASP.NET alternative to gallery.menalto.com ???
    By gicio in forum C# Programming
    Replies: 0
    Last Post: 05-15-2005, 11:31 AM
  5. 46 hours to assignment submission
    By technoXavage in forum Game Programming
    Replies: 9
    Last Post: 12-23-2003, 02:15 PM

Tags for this Thread


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