Could somebody tell me how to fix this compiling error?

This is a discussion on Could somebody tell me how to fix this compiling error? within the C Programming forums, part of the General Programming Boards category; Code: #define VARIED_LENGTH_STRINGS #ifdef VARIED_LENGTH_STRINGS char *copy; #else char copy[45]; #endif and the error I get is this: syntax error ...

  1. #1
    Unregistered
    Guest

    Could somebody tell me how to fix this compiling error?

    Code:
    	#define VARIED_LENGTH_STRINGS
    	
    	#ifdef	VARIED_LENGTH_STRINGS
    	
    	
    		char	*copy;
    	#else 	
    		char	copy[45];
    	#endif
    and the error I get is this:
    syntax error : missing ';' before 'type'

    the error points to the line char *copy;
    so I think the error is right before this line, but I can't figure out where the semicolon should go.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Need to see more code..... what comes before this lot?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Unregistered
    Guest
    it's at the start of a function... that's why i didn't include more code, but if it helps:

    Code:
    static int XYZ (char *a, int b, int c, int d, int *e)
    {
    	blength=addr2 - addr1 + 1;
      	
    	#define VARIED_LENGTH_STRINGS
    	
    	#ifdef	VARIED_LENGTH_STRINGS
    	
    	
    		char	*copy;
    	#else 	
    		char	copy[45];
    	#endif

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    In C89 standard C, variable must be declared at the top of a block. In your code the line
    >char *copy;
    is a declaration, and this is code:
    >blength=addr2 - addr1

    Try moving the blength=... line below the #endif line.

    Also, I presume these are global variables?:
    >blength, addr2, addr1
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Unregistered
    Guest
    that seemed to do the trick... now off to fight the battle with my link errors. Also, in response to your second question, yes all three are global variables.

    Thanks for your help Hammer.

    Peace

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 02:17 AM
  2. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 05:02 PM
  3. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 12:54 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM

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