Thread: Strange error I have not gotten before.

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    40

    Question Strange error I have not gotten before.

    I am getting the following error when I compile my program on gcc. two or more data types in declaration of `main'
    Also I want to print out the structure in one of my cases but won't let me call the structure and I don't understand. Please help.. I am new to this programming.


    Here is the code.

    Code:
       #include <stdio.h>
       #include <stdlib.h>
    
       int  num_comp;
       float  num_months;
    
       struct company{
          char city[30];
          float months[10];
          char name[20];
          char manager[20];
        }
    
       int main(int argc, char **argv){
    
           FILE *fp;
           struct company;
           char filename[20];
           int month,choice;
    
           printf("Please enter the name of the relevant file:  ");
           scanf("%c", filename);
           fp = fopen(filename, "r");
     
          printf("Please enter your choice:" );
           printf("1. Enter 1 to get the statistics for a specific month.");
           printf("2. Enter 2 to get the overall statistics.");
           printf("3. Enter 0 to terminate the program.");
    
    
           switch(choice){
              case 0:
              printf("Good Bye!");
              break;
              case 1:
              printf("Which month are you interested in? ");
              scanf("%d", month);
              break;
              case 2:
              printf("The statistcs are below: %s\n");
              break;
              default:
               break;
             }
          return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Your struct is missing a final ;
    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.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    40
    What is a final? please advise.

  4. #4
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    You're missing a semi-colon at the end of your structure (line 12).

    Also:
    Code:
    printf("The statistcs are below: %s\n");
    You're telling printf() to print a string but you're not telling it which string to print.

    EDIT: Also:
    Code:
    scanf("%c", filename);
    You really want a string, but you're telling scanf() to read in a single char.

    EDIT 2: Also:
    Code:
    scanf("%d", month);
    This is incorrect. You need to pass pointers to scanf() for it to store things properly.
    Last edited by itsme86; 09-16-2005 at 11:40 AM.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange error -- COM DLL is not installed correctly?
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 07-16-2007, 08:32 AM
  2. Strange results using dnsapi and windns
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-13-2005, 10:21 AM
  3. Strange response from MSVC
    By VirtualAce in forum Game Programming
    Replies: 2
    Last Post: 04-17-2004, 07:40 AM
  4. Very strange bug...
    By JaWiB in forum Tech Board
    Replies: 6
    Last Post: 04-27-2003, 01:56 PM
  5. bcc32 compiling error (really strange!!)
    By jester in forum C++ Programming
    Replies: 14
    Last Post: 01-26-2002, 04:00 PM