Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug existing C programs with Visual Studio 2010 Professional?

how can I use the Visual Studio Debugger on existing C programs I found in a textbook? I want to debug these little examples one by one, but without the overhead of creating a full project for each example.

Example: Let's say I compile "helloworld.c" from the Visual Studio command prompt ("cl.exe helloworld.c"). This gives me helloworld.obj and helloworld.exe. I would like to know if there is a way to use the VS debugger on "helloworld.exe". So far, I have only worked with the debugger on full-blown projects; I have no idea how to debug small "stand-alone" test programs without the Visual Studio project overhead. (I hope this is not a dumb question, as the VS Debugger might only be available for the full project.)

Thank you for any ideas.

like image 485
Rainer Avatar asked Oct 28 '25 21:10

Rainer


2 Answers

Why don't you create one project for testing the sample codes? You can create a single .c-file for all the samples. This would look something like

void sampleA()
{
 //hello world
}

void sampleB()
{
 //hello everybody else
}

void main(int argc, char** argv)
{
//  sampleA(); 
  sampleB();
}
like image 51
Philipp Avatar answered Oct 31 '25 10:10

Philipp


What I do when I have to use VS is to reuse the plain.c project I created a long time ago.

Just paste new code there and go. Throw the code in another file if you want to keep it.

like image 37
pmg Avatar answered Oct 31 '25 12:10

pmg