Thread: A beginner's problem

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    9

    A beginner's problem

    I am getting the syntax error message " ; before type char". I have searched high and low for a missing ";" but everything seems to be in the proper place. It is the last error in my program before a successful compilation.

    Please Help!

    Thanks!

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    Show us the code (using [code] tage (see my signature). Also what line is it giving the error on?
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    Ummm okay let me use my telepaty powers to c ur code throught ur mind !!!!! Post the code if u need a decent reply nun of use is harry porter u c
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  4. #4
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    It's just a hunch, but see if this is what's wrong

    Code:
    #include <stdio.h>
    
    int main(void)
    {
        int i;
        
        i = 2;
        	 
        printf("%d times %d is %d", i, i, i * i);
    	
        //  uncomment int l = 6 and recompile as is
    	
        //  int l = 6;
    	
        // Trying to create a variable here caused: 'syntax error : missing ';' before 'type'
    			
        // then try moving int l to the top and try it again.
    	
    	
        return 0;
    }
    Maybe that's it.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    9
    Thanks guys, my code was this:

    void listrecords()
    {fileptr=fopen("a:hospital", "r");
    char option;
    readfile();
    .......

    It finally dawned on me that my variables had to be declared first before opening the file. DUH!

    Now my output has some garbage in it (not from the above problem) I will try to solve that problem tonight. I just stumbled on this board - it is great to know there are people out there who are willing to hear the drivel of a newbie.

    Thanks!

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The problem is you're trying to use C++ variable declaration in C.

    int x = 1;
    printf("%d", x );

    The above is valid C code. The below is valid C++ code, and is not valid C code:

    int x = 1;
    printf("%d", x );
    int y;

    In C, all variable declaration must be at the beginning of the scope block.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. Beginner's Problem With First Funtion
    By Ohrange in forum C++ Programming
    Replies: 4
    Last Post: 04-19-2007, 06:59 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM