Menu

Programming

2002-12-05
2012-09-26
  • Nobody/Anonymous

    I am brand new to programming and i am using sams C in 21 days, dont really expect that to happen but hopefully i will have the basics down. Anyway i inputted the following code exactly as the book shows and i got a bunch of errors such as "Line 1 parse error before ' \'  but the weird thing is, is it tells me i have errors on lines 319 upto 333, and i am no where close to using that many lines.  OK i am using Dev C++ compiler the newest version, i believe its 4.9.7.0  and i saved this program as "first.c"  This is a C book not C++ or C#.  here it is.

    //Sample.c

    #include <stdlib.h>

    int main ( void )
    {
         printf("Dev-C++ program at work!");

         system("PAUSE");
         return 0;
    }

     
    • Nobody/Anonymous

      Your comment is C++ formatted, but, because you saved it as a .c format, its trying to compile as a C program.  It will compile as a C++ program

      I also doubt that you copied it down "exactly".   In addition to the above language error, you did not include stdio.h, which you need for printf to work.
      This code, based on yours, will compile and run as a C program:

      #include <stdlib.h>
      #include <stdio.h>

      int main ( void )
      {
      printf("Dev-C++ program at work!");

      system("PAUSE");
      return 0;
      }

      Wayne

       
    • Nobody/Anonymous

      Oops, im already able to do some hello world programs hehehe but i didnt know nothing about that comment things.

      So Wayne, when adding comments to C programs we should always use /* */ and for C++ programs we Can use bot // and /* */ , is that it ?

       
    • Nobody/Anonymous

      That is correct, you can use whichever suites your needs in C++.

      Note that once the stdio.h is added, the code compiles if you save it as a c++ file, i.e. waynesanidiot.cpp.

      Wayne

      p.s. don't let this put you off comments.

       
    • Nobody/Anonymous

      Thanks wayne.
      I did double check my typing and i did type it exactly as it shows on page 887 of sams learn c in 21days.  What is bugging me now is that this is supposed to be a C format book but you are saying that the format is in c++.  No wonder none of the programs I am typing from this book are working for me.  I will try them as C++ programs. Thanks again.

       
    • Nobody/Anonymous

      Could anyone please give me some advise?

      I am new to programming and about to start a programming coarse over the internet, anyway I am about to start C and I would like to know which compiler I should use? and any other general advise you could give would be great.

      Thanks

      Karl

       
    • Nobody/Anonymous

      See my post on the new thread you started, I recommend the LCC C compiler.

      Wayne

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.