Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8699317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:55:09+00:00 2026-06-13T01:55:09+00:00

I have the following code in C: while(tempNode!=NULL) { int pos = pathNodesCount-1-i; pathNodes[pos]

  • 0

I have the following code in C:

while(tempNode!=NULL) {
    int pos = pathNodesCount-1-i;
    pathNodes[pos] = tempNode;
    //printf("A");
    euclidianLength += tempNode->g;
    i = i+1;
    tempNode = tempNode->parent;
}

if I leave the printf("A") statement commented out, and then compile and run my code, I will get an “application stopped running” Windows error. If I uncomment the printf("A") line, recompile and run, the application will run to its end (printing “A” to the console along the way). Why?

The environment is:

  • Windows 7 32bit
  • MinGW32 20120426 (and I’ve added MSys 1.0)
  • Eclipse Juno for C/CPP

== UPDATE

I’ve tracked my error. I won’t post the exact code as it is too long, but it was a case of creating a char array, and then adding characters at wrong indexes. Something like this:

int otherCrap() {
    char* c = malloc(10*sizeof(char));
    int i = 0;
    for(i = 0; i<13; i++) {
        c[i]='a';
    }
    c[15] = '\0';
    printf("A");
    printf(c);

    return 0;
}

Fixing the thing so that the chars were placed inside the array only at existing indexes, and also ading ‘\0’ char as the last element in the array fixed the issue. However I’m still not clear as to why, when the code was bad, adding a printf(‘A’) before printing the char array didn’t result in a runtime error. From the answers received so far I am to understand that this falls under “undefined behavior”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:55:10+00:00Added an answer on June 13, 2026 at 1:55 am

    Probably because some error in the code causes undefined behavior. Having the code then appear to “work” in the presence of a printf() is fine.

    That indexing logic counting backwards looks scary; verify that it’s correct. Print the index before using it, compare to the known size of the pathNodes array, if you have one. Beware of the index turning negative or overrunning the capacity of pathNodes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code while(((line = in.readLine()) != null)) { String[] val =
I have the following web php code: while ($row = mysql_fetch_array($results, MYSQL_NUM)) { printf(<p>ID:
I have an exe file which has the following code: while(1) printf("hello\n"); I'm executing
I have the following code: while ($content = mysql_fetch_array($content2)){ echo $content[0]; session_start(); $_SESSION['content'] =
I'm working in Python. I have the following code: while not is_suffix(pattern[:k], pattern[:q]): k
I have the following code: Bear in mind that while this code works on
I have the following code in test.sh: while getopts f:i: opt; do case $opt
I have the following code that opens a new popup window while disabling the
I have the following code: void doPlayerMove(void) { bool moved = false; while (!moved)
I have the following code: $page=3; $i=1; while($i<=$pages) { $urls .= '.http://twitter.com/favorites.xml?page= . $i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.