How come Dev C++ cant run some programs??

This is a discussion on How come Dev C++ cant run some programs?? within the C Programming forums, part of the General Programming Boards category; ok im kinda new to C , and i have the c programming language 2nd edition book but when i ...

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    17

    How come Dev C++ cant run some programs??

    ok im kinda new to C , and i have the c programming language 2nd edition book but when i try to some of the programs from the book in it , it doesnt work!! I mean no errors show but the program isnt running the way is suppose to.

    For example, in the 1st chapter where theres 3 parts to characters ,words , lines, and other stuff counting programs, it shows no error while compiling but it doesnt show the output from printf. I have the newest version of dev c++ (i think 4.9.9.2)
    but it doesnt work; i tried to the settings and put options like
    "support all ansi standard c programs " and "attempt to support some aspect of traditional c programming" and it doesnt change a thing.

    please please please help! i am really stuck and dont know what to do.

  2. #2
    Registered User
    Join Date
    Dec 2003
    Posts
    50
    You might want to post your problem over at the Dev-C++ forum.
    The URL is http://sourceforge.net/forum/forum.php?forum_id=48211

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    22
    Try placing
    Code:
    system("PAUSE");
    just above return 0 in your source file.
    Then in the line counting program for example .Type some lines pressing enter .Then press Ctrl + z then enter.
    Last edited by phil; 09-09-2005 at 06:32 AM.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,335
    > it shows no error while compiling but it doesnt show the output from printf.
    Post your code.
    I've seen plenty of ways of messing this up which still compile, but which fail to run properly.
    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.

  5. #5
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    You're trying to compile the code as C, not C++, right?

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    it doesnt show the output from printf.
    Yeah, put a system("pause") or getche() before the return 0:
    Code:
    #include <stdio.h>
    
    int main(void) {
        printf("Hello, World!\n");
        getche();
        return 0;
    }
    With getche(), you can press any key, not just <enter>, to close the console.

    Post your program.
    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.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    You're trying to compile the code as C, not C++, right?
    Yes:
    it shows no error while compiling
    I think Sephiroth's program compiled, but the console flashed and dissapeared before [s]he could read it.
    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.

  8. #8
    ---
    Join Date
    May 2004
    Posts
    1,379
    I think getche() is non standard. Use getchar()

  9. #9
    Registered User
    Join Date
    Jun 2004
    Posts
    17
    ok this is the code

    Code:
    #include <stdio.h>
    
    main()
    {
          int c, i, nwhite, nother;
          int ndigit[10];
          
          nwhite = nother = 0;
          for (i = 0; i < 10; ++i)
               ndigit[i] = 0;
               
          while ((c = getchar()) != EOF)
              if (c >= '0' && c <= '9')
                  ++ndigit[c-'0'];
              else if (c == ' ' || c == 'n' || c == '\t')
                       ++nwhite;
              else
                  ++nother;
           
          printf("digits =");
          for (i = 0; i < 10; ++i)
               printf(" %d", ndigit[i]);
          printf(", white space = %d, other = %d\n",
                nwhite, nother);
    }
    ok the problem is not that the program terminates so fast that i cant see anything. I did the getchar() thing at the end. problem is that i see no output like there should be (for example the printf("digits =") ) . I just dont get it! why doesnt it show?! oh yeah and i saved and compiled it as a C source not c++.

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    There's a FAQ on what to do when your program goes away before you like it to. In short, run it from a terminal, or put something at the end to prevent it from exiting until you hit enter or what not:
    Code:
    while( (c = getchar()) != '\n' );
    Also, you can initialize arrays to zero (or anything really, provided you fill in all the elements manually, otherwise any you don't fill in default to zero) at declaration time:
    Code:
    int array[ SOMESIZE ] = { 0 };
    This will set the first array element to zero. All uninitialized elements, provided you have manually initialized at least one, will be zero filled. Note, this does not fill them with the value of the first element, but with zero. Consider:
    Code:
    int array[ SOMESIZE ] = { 1 };
    This doesn't fill them all with 1. It fills the first one with 1, and the rest with zero.
    Code:
    int array[ SOMESIZE ] = { 0, 1, 2 };
    This fills the first with zero, the second with 1, the third with 2, and the remaining with zero.


    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    Registered User
    Join Date
    Jun 2004
    Posts
    17
    no is not that the program window flashes and quits, the program is suppose to print an output counting the occurences of characters, words, lines, and other stuff but when i enter such characters, i receive no output.

  12. #12
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    The program is fine, Dev-C++ is fine. It is just that this program requires a little unusual input.

    1. Type in your input.
    2. Press ENTER.
    3. Press F6. This is the Windows EOF input key. It must be on a line by itself.
    4. Press ENTER.

    You can follow these last three steps whenever a program requires an EOF. You can see that this program reads input until it receives an EOF by this line:
    Code:
          while ((c = getchar()) != EOF)

  13. #13
    Registered User
    Join Date
    Jun 2004
    Posts
    17
    O ya!! it works now . ok i gotta get this straight 1 more time.
    so if the program or any program just require anything that has to do with EOF i have to do the F6 thing right? and if it doesnt call eof as an argument of any kind then i wont need to press F6 ever?

  14. #14
    Registered User
    Join Date
    Jun 2004
    Posts
    17
    oh sorry i forgot also one last thing, is there a way to set dev c++ to do the F6 thing automatically whenever eof is called?

  15. #15
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> so if the program or any program just require anything that has to do with EOF i have to do the F6 thing right? and if it doesnt call eof as an argument of any kind then i wont need to press F6 ever? <<

    Yes. Pretty much. You can also use a file as input. This is called redirection. In this case, the program will receive EOF (which stands for "end of file") at the end of the file. This example shows how to run a program using file.txt as the input.
    Code:
    >yourprogram < file.txt
    >> oh sorry i forgot also one last thing, is there a way to set dev c++ to do the F6 thing automatically whenever eof is called? <<

    No. How would it know when to supply the EOF? The EOF allows you to tell the program that you have finished supplying input. If your program only expects a single line of input, it might use the new line character to tell it when the input is complete.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual c++ 2005 express edition to run .c files
    By the_fall_guy in forum C Programming
    Replies: 4
    Last Post: 04-05-2007, 12:33 PM
  2. Dev C++ Won't Compile
    By mburt in forum Windows Programming
    Replies: 8
    Last Post: 08-21-2006, 11:14 PM
  3. Running programs - few stupid mistakes
    By Korhedron in forum C++ Programming
    Replies: 14
    Last Post: 03-10-2004, 02:10 PM
  4. Programs to run C applications
    By Mak in forum C Programming
    Replies: 3
    Last Post: 03-01-2004, 11:56 AM
  5. how to compile & run c programs in unix?
    By Unregistere in forum C Programming
    Replies: 2
    Last Post: 10-09-2002, 10:53 PM

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