Thread: expected identifier

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    3

    expected identifier

    Hi, I've been playing around with this idea of program which probably has been made already million times but i cant get mine working for some reason, its supposed to write numbers 1 to 10000 for now just with printf, but the idea is to get it to write it to textfile and in format: 00000 00001 00002 00003 and so on...

    Code:
    #include <stdio.h>
    
    int ruu = 10000;
    int var = 0;
     
    while (var <= ruu)
    {
     printf(var);
     var++;
    }
    my compiler says:
    error: expected identifier or '(' before 'while'
    Compilation failed.

    also, I'm on ubuntu 10.04 using Geany.

  2. #2
    Registered User
    Join Date
    Aug 2010
    Posts
    35
    No main procedure?

    Code:
    #include <stdio.h>
    
    int main (void) {
        int ruu = 10000;
        int var = 0;
        while (var <= ruu)
        {
            printf("%i\n", var);
            var++;
        }
    }

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    3
    Now it compiles but still gives:
    in function 'main':
    warning: control reaches end of void function

    what does this mean?

  4. #4
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    He did not explicitly add a return statement. Under C99, this is ok, but under C89, you must include a return:

    Code:
    #include <stdio.h>
    
    int main (void) {
        int ruu = 10000;
        int var = 0;
        while (var <= ruu)
        {
            printf("%i\n", var);
            var++;
        }
    return 0;
    }

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    35
    Put a return 0 at the end too.

  6. #6
    Registered User
    Join Date
    Aug 2010
    Posts
    3
    Thanks alot for the help, now it compiles and builds with no errors or warnings, it worked fine before adding the "return 0" but i prefer to learn these things properly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling Libraries in C
    By TheOriginalGame in forum C Programming
    Replies: 3
    Last Post: 08-15-2010, 11:19 AM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Why wont my function exit correctly?
    By LightsOut06 in forum C Programming
    Replies: 2
    Last Post: 10-09-2005, 09:23 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM