Thread: Old style stuff

  1. #1
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179

    Unhappy Old style stuff

    Ok I am using Microsoft's Visual C++ compiler and I am just playing around with unary math operators to see how they work and what they do so anyways, I decided to try a for(whatever) function and I almost got it except my compiler complains about me using "old style formal list" or something like that here it is:

    Code:
    printLine();
    {
    	for(c>0; c--)
    	{
    		printf("Line %d", c);
    	}
    }
    Ok that is what is messing up, I know it is because I have the semi colon after printLine() but if I don't put it it I get:
    "missing ';' before ')'"
    and 2 warnings as well, can anyone help out here please.

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    You need to create the variable C. Try something like this:
    Code:
    void printLine(void);
    {
    	for(int c=80;c>0; c--)
    	{
    		printf("Line %d", c);
    	}
    }
    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >printLine();
    Lose the semicolon. The reason this is considered old style is because the parameter list for the function is empty. An empty list according to K&R C means an unknown number of arguments. ISO C requires that a function which takes no parameters is declared as void:

    printLine ( void )

    You also need to define a return type since the new C99 standard doesn't allow implicit int by omitting a return type.

    >for(c>0; c--)
    c is not decared anywhere and a for loop has three parts, initialization, condition, increment:

    int c;
    for ( c = someval; c > 0; c-- )

    -Prelude
    My best code is written with the delete key.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You need to create the variable C. Try something like this:

    for(int c=80;c>0; c--)
    This is not valid C code, unless the newer standard introduced C++ style variable declaration. You cannot just introduce a new variable in the beginning of a for loop in C. You'd have to declare 'int c;' on the line before the loop.

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

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >unless the newer standard introduced C++ style variable declaration
    It did, but it's still best to remain conformant to C89 until the new standard is in full use.

    -Prelude
    My best code is written with the delete key.

  6. #6
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Ok, I got rid of the semi colon put in void and then for the error that it gave me about the for() thing, I just had to make it complete by not defining the variable c before hand, I just changed it to:

    for(c=5; c>0; c--) and it workd, thanks a lot though
    Last edited by CAP; 07-09-2002 at 04:18 PM.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Concatenating C style Strings Question
    By bengreenwood in forum C++ Programming
    Replies: 3
    Last Post: 03-19-2009, 03:19 PM
  2. Your stuff
    By smog890 in forum C Programming
    Replies: 6
    Last Post: 06-13-2002, 11:50 PM
  3. How to change window style at runtime?
    By Mr. Bitmap in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2002, 04:49 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. how do I extract a style from a DWORD style
    By zMan in forum Windows Programming
    Replies: 1
    Last Post: 01-17-2002, 10:09 AM