Is there a problem with Dev C++?

This is a discussion on Is there a problem with Dev C++? within the C Programming forums, part of the General Programming Boards category; im new to c programming and im trying to learn it from "the c programming langauge" book and theres a ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    20

    Is there a problem with Dev C++?

    im new to c programming and im trying to learn it from "the c programming langauge" book and theres a little problem i dunno how to solve.

    Code:
    #include <stdio.h>
    
    main()
    {
          double nc;
          
          for (nc = 0; getchar() != EOF; ++nc)
              ;
              printf("%.0f\n", nc);
              
              getchar();
    }
    shouldnt this char counting program output nc only after EOF and not after every newline?? cause when i ran it, every time i pressed enter to a newline, it would show the value of nc, i mean shouldnt printf only be active only after EOF???

    o and another thing, also the output comes out as many numbers, y isnt the ouput showing only 1 number of nc but showing every incrementing process??

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    First, "int main()" (and possibly a return 0; ).

    Second, it's not a problem with Dev-C++. Dev-C++ isn't a compiler - it's an IDE. A fancy text editor. MinGW is your compiler, and it's extremely unlikely that there's a problem with it.

    Finally, I cannot reproduce your results. Are you sure you're compiling what you posted? My results:
    Code:
    C:\...\Projects\cboard>gcc -Wall -o prob.exe prob.c
    prob.c:4: warning: return type defaults to `int'
    prob.c: In function `main':
    prob.c:12: warning: control reaches end of non-void function
    
    C:\...\Projects\cboard>cat testp.txt
    hi
    hi
    hi
    hi
    
    C:\...\Projects\cboard>cat testp.txt | prob
    16
    
    C:\...\Projects\cboard>_
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    20
    yes it is exactly what i put in it, and for the "main" stuff,
    the author of the book never uses int main he only puts main, and i also put in a random message printf before the for loop and it doesnt even show! i dunno whats wrong with this thing.... the printf after the semicolon should only show after EOF but ..... uhh.... i mean it only should be like this if it was a while loop and the printf was in the body of the loop right?

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    20
    also another problem now....

    Code:
    #include <stdio.h>
    
    main()
    {
            double nc;
            
             nc = 0;
            while(getchar() != EOF)
                     ++nc;
                 printf("ld\n", nc;)       /* btw thats a L not a "one" */
           
               getchar();
    }
    for some reason, after typing a bunch of characters and going to EOF, the output is always 0?!!!! im really confused right now.....

    btw my dev c++ is 4.9.9.2

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    Don't use the increment operator on floating point numbers. You should be using a long not a double. Also, even if you were to use a double, you'd pass "%u" or "%f" to printf() not "%ld". "%ld" is for long decimal.

    ...and for future reference. Please copy/paste the ACTUAL code when you give an example. Not a syntax error riddled piece of garbage you typed up in 20 seconds. ...And main returns an int.
    Sent from my iPad®

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Get another book.

    How old is your book? If it's like, more than 10 years or so, it may be out of date. Or maybe the author's just an incompetent @$$-O.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    > printf("ld\n", nc
    Start by posting the code you actually tried!
    1. This doesn't compile
    2. Even if you fix the position of the ;, then there is no % to cause a conversion
    3. %ld is not how you print doubles.

    Makes me think that version 1 of the code was also lacking a ; at the end of the while loop.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You might want to try reading the tutorials or the FAQ or maybe a newer book.

    Also try compiling with compiler warnings on.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    To anyone that frequently uses Dev-C++:

    1) Why does dev-c++ not explicitly state when its using a C compiler vs C++ compiler
    (I've heard .c files imply that it is using a C compiler, but it does not state so explicitly when making/compiling single source files)?

    2) Where are the step, step-over, step-to, and breakpoint commands for dev-C++ (I thought those would be pretty standard for all IDEs...)?

    3) why does it contain perpetual whitespace? (if you hold down rightarrow it will continue to go on into an infinity of white space instead of advancing to the next line)

    4) why is the mouse cursor not accurate (i.e. when placing the mouse cursor between to characters and clicking, the cursor will actually be placed 1 character before where it should be)

    Are there any other better & free C/C++ IDEs out there ??
    Thanks

  10. #10
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    1) You tell it C/C++ when you create a project. Otherwise, mine appears to always use g++, but I believe it's the nature of g++ (and gcc too?) to compile based on the file extension.

    2) Click the "Debug" tab. For breakpoints, click in the gutter.
    3) Er... mine doesn't do that?
    4) Mine doesn't do that either?
    (Edit: Fired up my old, old version of Dev-C++ (version 4.0), which does exhibit the complaints you listed. I use 4.9.9.0 - a version 5 beta. Which I prefer over the old one.)

    Yes, there are better IDEs! Frankly, I rarely use Dev-C++, I usually code in Textpad or Notepad++, write my own Makefiles, and compile on the console.
    And... OT? Perhaps better for a new thread than this one?
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  11. #11
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    thanks alot!
    As it turns out, I was a bit cautious about using the beta, but now I hear how much its better than 4.0, I think its worth a try.

    .... hmm, Dev-C 4.0 had no problems installing into any directory, and now the newer version, 5.0, won't install into any path with spaces in the name.... I hope they fix that for the final release.
    Last edited by @nthony; 07-03-2006 at 11:43 PM.

  12. #12
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    Quote Originally Posted by Cactus_Hugger
    but I believe it's the nature of g++ (and gcc too?) to compile based on the file extension.
    I don't know about that. At my school, when running on SunOS, g++ is g++ and gcc is gcc. That is to say, g++ will compile as c++ regardless of extension and gcc will compile as c regardless of extension. Compilers just take whatever you give them and see if it all makes sense. If it doesn't it gives you errors... it doesn't care what the extension is.

    The same seems to apply under Windows, as I just tested.
    Last edited by SlyMaelstrom; 07-03-2006 at 11:49 PM.
    Sent from my iPad®

  13. #13
    Registered User
    Join Date
    Jun 2004
    Posts
    277
    Quote Originally Posted by jafet
    Get another book.
    Or maybe the author's just an incompetent @$$-O.
    This is a great quote about K&R Man
    Code:
    main () {}
    Is valid C according to gcc 4.0.

    main defaults to in in gcc afaik.
    gcc -Wall void.c -o void
    void.c:3: warning: return type defaults to ‘int’
    void.c: In function ‘main’:
    void.c:4: warning: control reaches end of non-void function
    yep I was right

  14. #14
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,438
    Quote Originally Posted by @nthony
    1) Why does dev-c++ not explicitly state when its using a C compiler vs C++ compiler
    (I've heard .c files imply that it is using a C compiler, but it does not state so explicitly when making/compiling single source files)?
    Click Tools->Compiler Options->Programs.

    The executable for the gcc label compiles C code. The executable for the g++ label compiles C++ code. For MinGW these are gcc.exe and g++.exe respectively.

    Next... click Project->Project Options->Files.

    Each file on in your project that is to be compiled as C++ code should have "Compile as C++" checked. You usually don't need to change this setting since when creating a new project you define if you are creating a C++ or C project.

    You can also edit your .dev file with a text editor.

    Quote Originally Posted by @nthony
    2) Where are the step, step-over, step-to, and breakpoint commands for dev-C++ (I thought those would be pretty standard for all IDEs...)?
    It's, as I see it personally, the weakness of Dev-C++. The gdb graphical interface leaves a lot to be desired. However it's all there. Compile with the -g3 to generate debug symbols. Then you can just click on the icon with a check mark next to the build buttons to enter debug mode.

    gdb is an excellent debugger. I'm slowly getting used to debug in the command line instead of Dev-C++ or Insight. The transition is slow, but I highly recommend it. Insight is a UI for gdb. However the windows version is old and probably abandoned (as it seems Dev-C++ itself is about to become).

    I strongly suggest you start considering debugging on the command line. Once you get used to it, it's not much slower than graphically and you get a lot more control.

    3) why does it contain perpetual whitespace? (if you hold down rightarrow it will continue to go on into an infinity of white space instead of advancing to the next line)
    Click Tools -> Editor Options. Uncheck "Cursor Past EOL"

    4) why is the mouse cursor not accurate (i.e. when placing the mouse cursor between to characters and clicking, the cursor will actually be placed 1 character before where it should be)
    This doesn't happen. Sorry. Some problem on your side. Only other thing I can think of is if you are doing this in Overwrite mode. On that case, yes... your cursor will shift one character. But that's windows standard behavior. pressing the "Insert" key will obviously solve this.

    Are there any other better & free C/C++ IDEs out there ??
    Thanks
    No. Not in my opinion. But you can try Code::Blocks. I personally prefer Dev-C++. There's a new version comming soon for Code::Blocks (RC3). Probably it will address a few of the issues I have with it.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  15. #15
    Registered User
    Join Date
    Jul 2006
    Posts
    20
    i dunno why u say to post the actual code that i tried??? this is EXACTLY what the book says and what i tried.

    about getting another book, what do u recommend is good?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  2. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  3. Problem running prog I wrote in Dev C++
    By KidMan in forum C Programming
    Replies: 8
    Last Post: 09-22-2005, 01:50 AM
  4. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21