Thread: Editor

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    13

    Editor

    Hi

    So I recently started to program with C again. That's why i called this one "FirstProgram"
    (I do not have a lot of experience, so please forgive huge mistakes)

    I think there is a problem with my editor or compiler (Code::Blocks)

    Here's the code with which I first noticed that something is wrong..
    (There also may be some mistakes in there, please correct me if so.)


    Code:
    #include <stdio.h>
    
    int anzahl
    
    int main()
    {
        printf ("Number of Integers: ");
        scanf ("%d", anzahl);
        int Numbers[anzahl];
        for (i = 1; i = anzahl; i++)
        {
            printf ("%d. Number: ", i);
            scanf ("%d", Numbers[i-1]);
        }
        for (i = 1; i = anzahl; i++)
        {
            printf ("\n\n%d.Number", i);
        }
    }
    If I start this program ("Run" or "Build" and afterwards "Run"), I immediately get the Output which I attached.
    I thought it was strange that I wasn't asked for entering a number, so I tried to change the code to something like that


    Code:
    #include <stdio.h>
    
    // int anzahl
    
    int main()
    {
        // printf ("Number of Integers: ");
        // scanf ("%d", anzahl);
        // int Numbers[anzahl];
        // for (i = 1; i = anzahl; i++)
        {
            // printf ("%d. Number: ", i);
            // scanf ("%d", Numbers[i-1]);
        }
        // for (i = 1; i = anzahl; i++)
        {
            // printf ("\n\n%d.Number", i);
        }
        printf ("Hello");
        return 0;
    }
    (I took away almost everthing and wrote "printf ("Hello");" and a return)

    If I now do "Run" or "Build" and "Run", I get the same Output as last time...


    I don't get it... Maybe I just don't know how to work with Code::Blocks
    Please somebody help me...
    Attached Images Attached Images Editor-firstprogramout-png 

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    In the for loop you have an error:
    Code:
    for (i = 1; i = anzahl; i++)
    This code will assign i the number 1. Then it will assign i the value of anzahl. That's not what you want. What you want is:

    Code:
    for(i = 0; i < anzahl; i++)
    Counting in C nearly always begins with 0, not one. Which is handy because i < 10 (for example), will print out 10 values, without having to fuss around with i <= 10 or some other nonsense. Try and memorize that idiom: i = 0; i < howEverManyValuesYouWant; i++.

    If later on, you want to test a value for equality, be sure to use TWO == char's, not one:
    if( i == 5) do something
    Last edited by Adak; 09-10-2011 at 05:33 AM.

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    13
    Ok, thank you for this reply, you're right.
    But still, it doesn't solve my current problem..
    I still get the same output.

    Am I doing something wrong with the "Build" ?
    I think the problem is, that it doesn't run what I wrote but it runs what I first built (and doesn't re-build the new code). You know what I mean?

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    If you check the logs (typically near the bottom of the Code::Blocks window, unless you have reconfigured Code::Blocks) you should see informational messages reporting whether your source files are being compiled and linked (or any errors in the process). If you don't see those messages after attempting to do a build, then something is wrong.

    Code::Blocks (like a lot of other IDE's that run command line compilers behind the scenes) is a little temperamental sometimes, and decides not to rebuild your code if you have executed a previous version. You will see that with an absence of messages about compiling and linking in the log window, and apparentlyrunning a previous version of your program. One way to force the issue is Build/Clean (which deletes all compiled objects and executables) before attempting to build and run.

    You should find that the code you showed in your first post will not compile. The reason is a missing semi-colon (which has a way of confusing C and C++ compilers). That tends to result in deleting the object file, but can leave previous versions of the executable intact, which is why you seem to be executing an old version of the program.

    Adak has pointed out other problems with your code.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Sep 2011
    Posts
    13
    If I press "Build", the "Build Log" - Window is cleared. (Before, there was some successful execution information of an earlier execution.)
    If i remove the "FirstProgram.exe", which is the compiled program (i guess?), and then press "Run" I get the attached message. I click "Yes" and nothing happens (just the information window is closed)
    If I continue doing this, still nothing happens, but if I hit "No" one time it says "Process returned 0 (0x0) execution time : 0.000s, press any key to continue" in the usual black window. (What usually is written at the end of a successful program)

    It's really strange..

    Maybe I should try another compiler, any suggestions?
    Attached Images Attached Images Editor-builderror-png 

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Click on Yes, not No.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    Registered User
    Join Date
    Sep 2011
    Posts
    13
    I did, and i wrote that in my last post
    Quote Originally Posted by Eizi
    I click "Yes" and nothing happens (just the information window is closed)

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Then do a build clean, as I described, before trying to build for real.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  9. #9
    Registered User
    Join Date
    Aug 2011
    Posts
    1
    Hi Eizi,
    are you trying to write a program that prompts the user for the number of elements of an array,
    then prompts the user for each element of that array,
    and then prints out each element at the end of the array initialization process?

  10. #10
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Eizi View Post
    Hi

    So I recently started to program with C again. That's why i called this one "FirstProgram"
    (I do not have a lot of experience, so please forgive huge mistakes)

    I think there is a problem with my editor or compiler (Code::Blocks)
    The problem is with you code...
    You got the first result because your code is mis-ordered.
    The second result is because your code has errors and did not recompile.

    Go into your compiler settings in Code::Blocks and set the error and warning levels to maximum and pay attention to the reports you get... The compiler isn't just making noise it's telling you what your mistakes are...


    Code:
    #include <stdio.h>
    
    int main( void )
    {  int anzahl = 0;
        printf ("Number of Integers: ");
        scanf ("%d", anzahl);
        int Numbers[anzahl];
        for (i = 0; i < anzahl; i++)
        {
           printf ("%d. Number: ", i);
           scanf ("%d", Numbers[i]);
        }
        for (i = 0; i < anzahl; i++)
        {
            printf ("Number[%d] = %dn", i,Numbers[i]);
        }
    }
    Also note that run time array definitions as in...
    Code:
        printf ("Number of Integers: ");
        scanf ("%d", anzahl);
        int Numbers[anzahl];
    ... are a C-99 trick that will not work on all compilers.

    Also you should get yourself hooked up with the Code::Blocks forums where you can ask IDE specific questions and I believe they have tutorials there as well...
    Last edited by CommonTater; 09-10-2011 at 08:24 AM.

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Scanf() needs the address of the variable you want it to change, so change your lines of code with scanf() from this format:
    Code:
    scanf ("%d", anzahl);
    
    to
    
    scanf ("%d", &anzahl);

  12. #12
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    Scanf() needs the address of the variable you want it to change, so change your lines of code with scanf() from this format:
    Code:
    scanf ("%d", anzahl);
    
    to
    
    scanf ("%d", &anzahl);
    Good catch, Adak!
    Same with the second one...

    (How did I miss that?)

  13. #13
    Registered User
    Join Date
    Sep 2011
    Posts
    13
    Thank you all for your answers.
    @grumpy: The "Clean" operation is disabled (grey)
    @Gustav Nobleman: Yes
    @CommonTater: I changed the code exactly to what you posted, and I also activated warnings and errors, but the result didn't change...

    I also tried another thing.
    I already had some other little programs, which were examples of the tutorial with which I "learned" C-programming.
    I took one of those, saved them in another folder, to not get lost of them, took the editable file of the example and replaced the code with the code I previously posted here (I also corrected it).
    Then I built the new code in the old file and started it... Big surprise, the output was exactly what the example which i replaced should do. In other words, it wasn't re-built again..
    Last edited by Eizi; 09-10-2011 at 09:54 AM.

  14. #14
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The next question would have to be: do you actually have a compiler? (Code::Blocks is not a compiler, and needs one to actually do the compiling.)

  15. #15
    Registered User
    Join Date
    Sep 2011
    Posts
    13
    Hmm.. Since I just started to program again, it would be possible, that Code::Blocks still is on my computer, but the compiler is not.
    (Maybe unintentionally deleted by myself or something like that)
    Good thought, strange that I didn't realize it myself...
    If I actually don't have one, what could I do to get one/install one, and which one would you recommend?

    edit: But if I go on "Settings -> Compiler and Debugger..." it says: "Selected compiler: GNU GCC Compiler"
    Last edited by Eizi; 09-10-2011 at 10:07 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. editor
    By umair in forum C Programming
    Replies: 3
    Last Post: 03-16-2010, 06:48 AM
  2. Which Editor
    By Troubled in forum General Discussions
    Replies: 6
    Last Post: 08-12-2009, 11:42 AM
  3. C editor...
    By sunny_master_07 in forum C Programming
    Replies: 15
    Last Post: 09-15-2007, 12:49 PM
  4. S3D Editor
    By Queatrix in forum Tech Board
    Replies: 3
    Last Post: 07-12-2006, 04:05 PM
  5. What editor do you use?
    By esbo in forum Tech Board
    Replies: 9
    Last Post: 05-05-2006, 12:09 AM