Thread: preprocessor!!

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    12

    preprocessor!!

    i was typing a simple code in my c ide,i got stuck through a problem, plz help me out!!






    Code:
    #inlcude <stdio.h>
    main()
    {
    
    for (x=1; x<10; x++);
    	 printf("%d\n",x);
     }

    i got the rror message, Compiling NONAME02.CPP:
    Error NONAME02.CPP 1: Unknown preprocessor directive: 'inlcude'
    Error NONAME02.CPP 5: Undefined symbol 'x' in function main()
    Error NONAME02.CPP 6: Call to undefined function 'printf' in function main()
    Warning NONAME02.CPP 7: Function should return a value in function main()

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is just a typo error. "#inlcude <stdio.h>" should be "#include <stdio.h>", or "#inlcude <cstdio>".

    Of course, other potential problems include:
    1. a missing return type for main (should be int)
    2. x is used without being declared
    3. the for loop has a semi-colon that makes the loop do nothing.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    you probably also want to remove the last semicolon on the for() loop line
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  4. #4
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Quote Originally Posted by laserlight
    It is just a typo error. "#inlcude <stdio.h>" should be "#include <stdio.h>", or "#inlcude <cstdio>".
    Or "#include <cstdio>"

  5. #5
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Quote Originally Posted by Frobozz View Post
    Or "#include <cstdio>"
    it seems that teh typo disease has gotten laserlihgt too.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It is called copy and paste error, not typo error
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    just to summarize things said above, here is the (hopefully) correct code:

    Code:
    #include <cstdio>
    int main()
    {
    for (int x=1; x<10; x++)
    	 printf("%d\n",x);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C/C++ preprocessor directives
    By coletek in forum C++ Programming
    Replies: 11
    Last Post: 01-11-2009, 04:24 PM
  2. Writing an HTML Preprocessor
    By thetinman in forum C++ Programming
    Replies: 1
    Last Post: 09-17-2007, 08:01 AM
  3. Preprocessor Directives Problem
    By MipZhaP in forum C++ Programming
    Replies: 6
    Last Post: 02-18-2005, 01:53 PM
  4. Preprocessor string pasting fun
    By ggambett in forum C Programming
    Replies: 6
    Last Post: 11-11-2004, 06:40 PM
  5. Preprocessor Functions
    By mart_man00 in forum C Programming
    Replies: 2
    Last Post: 01-09-2003, 09:58 PM