Results 1 to 6 of 6

Thread: what is the syntax error here?

  1. #1
    Join Date
    Jan 2006
    Posts
    163
    Rep Power
    0

    Default what is the syntax error here?

    first off all let me say i am new C and just playing around with the language in a quest to learn it.

    #include <stdio.h>

    int main(int argc, char *argv[])
    {
    FILE *fp;
    fp=fopen("C:\\Documents and Settings\\Administrator\\Desktop\\test.txt","w");
    fprintf(fp,"hellow world\n");
    fclose(fp);
    int i;
    getche();
    return 0;
    }
    can any one please tell me why this pice of code is not compile, using of what i know in c++(which is not a lot) i don't see a syntax error. I thank you in advance for your replies.
    you cry i' wipe away all of your tears
    you scream i fight away all of your fears

  2. #2
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    what was the error message?

  3. #3
    Join Date
    Sep 2004
    Posts
    2,229
    Rep Power
    0

    Default

    Quote Originally Posted by leoandru
    what was the error message?
    error C2065: 'getche' : undeclared identifier

    hmm..its C and not C++..

    -_- cant help u there..
    Last edited by don_corleone; Apr 28, 2006 at 12:54 PM.

  4. #4
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    ok, ah.
    add
    #include <conio.h>.


    C++ on windows is retarded

  5. #5
    Join Date
    Jan 2006
    Posts
    163
    Rep Power
    0

    Default

    oh i forgot to say the language.......sorry.....its C
    you cry i' wipe away all of your tears
    you scream i fight away all of your fears

  6. #6
    Join Date
    May 2003
    Posts
    229
    Rep Power
    0

    Default

    Another issue is the declaration

    int i;

    In C all declarations must be at the top of a statement block (i.e. you have to put the declaration of "i" at the top with the declaration of "fp".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •