问题描述:

I´m using Visual Studio 2013 on a Windows 7 32 bit OS and I want to run some very simple C code.

Hint1: All my code is in the same project --> and same code page!

Running the first code of a simple calculation gives me the correct result which is ok, see task 1:

// Task 1

#include "stdafx.h"

#include <stdio.h>

#include <string.h>

int main()

{

printf("4 + 6 / 2 = %i", 4 + 6 / 2); //Result = 7! -->Correct!

getchar();

return 0;

}

Then I put the above code (of task 1) in comment and add task 2:

/* Task 1

#include "stdafx.h"

#include <stdio.h>

#include <string.h>

int main()

{

printf("4 + 6 / 2 = %i", 4 + 6 / 2); //Result = 7! -->Correct!

getchar();

return 0;

}*/

// Task 2

#include "stdafx.h"

#include <stdio.h>

#include <string.h>

int main()

{

int x, y;

printf("PROGRAM:\nPlease type x ");

scanf("%i", x);

printf("\nPlease type y");

scanf("%i", y);

printf("\nx * y = %i", x*y);

printf("\nx / y = %i", x/y);

printf("\nx % y = %i", x%y);

getchar();

return 0;

}

What happens now when I execute the code is that it gives me the result of the previous code of task 1. So it seems like that it executes the previous code, but it should not do that because that code is now in comment. It should execute the second code from task 2.

Does somebody know why the new code of task 2 does not get executed?

How can I prevent/ the first code from executing?

Even if I delete the code of task 1 (from the code page) --> save it and close Visual Studio Program and reopen the project. When I run again the code (which has visually only the code of task 2 in the code page) it shows me the result from the previous task 1.

There is maybe a wrong setting, but where and what exactly?

Would be super if somebody could help me out please.

Hint2: The source file itself is still saved as .cpp but shouldn´t be the reason, correct?

I also changed this "Settings": --> Project --> Properties --> Configuration Properties --> C/ C++ --> Advanced --> Compile AS: Compile as C Code (/TC)

There is no change, same error behaviour!

网友答案:

It could be that it is not using the new version, i.e. compiled. Try and run the "Clean" on the project via the project >> right-click >> Clean. Then rebuild and retry. Sometimes between the obj, build, debug folders things get confused.

网友答案:

Make sure you aren't running an old version of your build. Do a rebuild all, and then make sure your dealing with an up to date build by going into your projects directory, selecting the project, and when you reach the complete build (should be an .exe now) check the date and time are current.

Otherwise, as others suggested, you might need to "clean" your build.

网友答案:

whenever the code you see "can't" be the code that is executing there are two possibilities

  • old object code is being run... rebuild should fix... clean and build will fix.
  • you have an old process that is still alive, the fix is: close and check for any old running processes... and kill them.

there are some trickier scenarios:

  • you think you are running old code because you missed a breakpoint - this could mean your breakpoint got optimized out or you don't have debug symbols
  • you are running old code from a dynamic library that is getting picked up rather than the library you are compiling... that is much trickier to discover and fix.
相关阅读:
Top