The system cannot find the file specified while programming C - c

Ok so I'm using Visual Studio 2017 on Windows 10. I'm wanting to use it to program in C. When I tried making a program, I got this one error "Unable to start program 'C:\Users\XXXX\source\repos\TestingProject\Debug\TestingProject.exe'. The system cannot find the file specified."
I looked around, and some people said it's due to faulty code that should bring up errors while compiling. There were a few issues, and I solved them to the best of my ability, but still can't get it to run. Since I can't figure out how to get Visual Studio to tell me specifically what's wrong (maybe if someone could tell me how I could get Visual Studio to say underline what piece of code doesn't make sense) I instead tried making and running a simple hello world program. However, I still got the error.
Here's the Hello World program code:
#include <stdio.h>
int main()
{
printf("Hello World! This is Just a test.");
return 0;
}
It still gives me that one error, and I don't know how to fix it. Also, if someone could tell me how to make Visual Studio do error checks while writing code, please tell me how. If anyone can help, I'd appreciate it.

It seems that the whole issue was down to the C file not actually being inside the project itself. This is quickly solved by looking at where the file is located by looking at the properties window, then locating the file, followed by copying the file and pasting it inside the "Solution Explorer" window.
Now, it actually shows me the error checks and what errors the code has. When I now create a "Hello World" program, it opens a separate window and prints out "Hello World!".
I must've thought that since I had the project open, and then opening a file from my desktop, that it could run perfectly fine. Just need to keep this in mind next time.

You can always try File -> Move .cpp into -> then select your project folder.
This worked for me.

You can always try File -> Move .cpp into -> then select your project folder.

Related

F0520005:Could not open source file "r_bsp_config.h"

i'm working with renesas MCU RX65N, i want to make a serial connection with other board and also display an HMI i designed on Appwizard, i followed the steps they offer on their manuals but won't work either. Then found more information about how to solve it, and the code works by itself, but when i try to merge both programs just keeps giving me errors (problems that doesn't appear on individual projects), this is the error i got now, and don't know what to do because apparently it is included for my project but won't open no matter what i try, anyone knows how to solve it or what to do?
It sounds like when you include the file in one project, it works, but when you include it in another project, it doesn't? It sounds like there is a configuration difference between your projects. Try creating a new file in a project, then just put #include "r_bsp_config.h" in it, or however you wrote it (it may need to be #include <r_bsp_config.h>). See if you get the same error (you will probably get an error, something about missing main(), but the question is whether you get the same error). If you don't, cut and paste the code from the problematic project in, and also make sure the project configuration is adjusted to match, and see if it works now. If you do get the same error, then see if you can copy the project configuration from the working project to the new project, and see if you get the error this time.

Microsoft Visual Studio 2017 VERY basic help needed: "The system cannot find the file specified"

I'm doing an Introduction to C Programming course at the moment, only just started, and I am running into an issue I just can't get around. The course instructor is no help, and I know the issue is extremely basic, but every solution I find online assumes good working knowledge of the software. I don't have that, not yet anyway.
I'm simply trying to run the following code:
#include <stdio.h>
int main(void)
{
printf("Hello");
getch();
return 0;
}
This is, I believe, supposed to display "Hello" on the screen when I run it. But when I press F5 to debug I get the following message:
"Unable to start program. '[file path].Project1.exe' The system cannot find the file specified."
So there needs to be a .exe file there, but how do I make one? I've searched through many other answers to similar issues across the web, but all of them make reference to things I simply don't understand yet, so I'm asking here for a layman's explanation of how to resolve this.
Thanks so much to anyone who can help.
In your output window you are currently seeing that message in the Debug, right? You need to change that to Build or (I prefer) Build Order (which keeps the multi-threaded items in a sensible order for output). This will show you why your program didn't build - hence you have no "exe" to run.

Why does Visual Studio keeps running an old project?

I had an old project I was working on previously, just to keep it simple let's say the project is a calculator.
Today, I opened Visual Studio, selected a new project, and add a source file helloworld.c. If I leave the whole file empty and press f5 (start debugging), it gives me the error there is no entry point, which is expected.
However, once I add in the code for helloworld.c and try to start debugging, I get an error about multiple instance of "main". So then I remove the main from helloworld.c and try pressing start debugging again, and now for some reason it runs my calculator program. I have no idea why is this is happening. I don't have the old program running at all and I haven't touched it, how can I stop Visual Studio from running this project??
Thanks
Edit: seems like this only happens when I have "#include <'winsock2.h>", but im not sure why this would be related... (ignore the ')

Unable to start program, cannot find the file specified, Visual Studio 11

I'm working off of a fresh install of VS 11 Beta, on a Windows 7 64-bit machine. When I try to debug, it gives me this error message.
"Unable to start program 'C:\Users\myname\documents\Visual Studio 11\Projects\Project1\Debug\Project1.exe"
I'm almost entirely sure it isn't a problem with my code--it works fine on online compilers, making me think that it's an issue with how I'm saving it. Just in case, here it is.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("Hello, world!\n");
return 0;
}
My process for creating the project/file is to create a new empty Visual C++ project, then a .cpp file, write my code, save it as a .c inside of the first folder I'm prompted with, within the projects folder, and then try to debug.
What am I doing wrong, here? I know that the debug folder is empty, but I can't figure out how to create the .exe file that should reside in it.
NB: I'm rather new to programming. If answers could be phrased in babyspeak, that would be appreciated.
Well, there could be a number of things wrong. However, based on your description of making a ccp file and a c file, I'm betting that it's a problem in your VS 11 project rather than the code itself. My guess would be that either the c file didn't get included in your project (check the Solution Explorer) or that you have the main (or _tmain) function defined in both the cpp and the c files, which will make the linker issue an error.
There are a bunch of "Hello World" tutorials online for VS 2010 and earlier, but there don't seem to be many for VS 11 Beta yet. You may want to take a look at the 2010 versions. I found this video tutorial that you may want to check out.
Check the output directory. And you can also set manually an output direcotry to save the built exe file.
I know this problem was from May but I thought I would answer with a solution that worked for me:
I was creating a .cpp file in a blank project and was getting a similar error. I noticed that the file had a name but was not showing the extension .cpp. I added the extension to the file (ex3.18.cpp) and did not get the .exe error again.
I don't know if that makes sense with your issue but I worked on this for two days uninstalling and reinstalling VS 11, and this was what finally worked.

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.
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();
}
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.
If you're set on not using projects then you can do this. It just gets more difficult as the number of code files increases.
First, to do any meaningful source-level debugging, you will need to generate debug symbols. Add the "/Zi" switch to your cl.exe command line:
cl.exe /Zi helloworld.c
This will generate helloworld.exe, helloworld.obj, and helloworld.pdb (these are the debugging symbols).
Next you will open Visual Studio 2010. Use File -> Open -> File... and select helloworld.exe. It will generate a wrapping solution with one project for your EXE file.
In Solution Explorer, right click on the EXE file and select Debug -> Step Into new instance.
It should pop up a source window and show you the first line of your program. Now, debug away!
The debugger is part of Visual Studio, so you'll have to start it up anyway. However, for the debugger to work properly with your source code, you need to also generate a PDB file (see here). You get this by including /Zi or /ZI as argument to cl.exe (see here).
It is not impossible, but you'll have to learn a lot more about how to exactly build a program from the command line to get the best debugging experience. There are a bunch of options that are real time savers and greatly improve the odds that you'll discover bugs.
Which is a little beside the point right now, learn C instead of spending time learning a boring tool with way too many options. Creating a new project takes 5 seconds after a wee bit of practice. Use the Win32 Console Application project template.
One small setting you have to change if you want to compile as C instead of C++. Right-click the project, Properties, C/C++, Advanced, Compile As = Compile as C Code.
The "overhead" is hardly more effort that it took to post this question!
Simply start with the "Empty Project" template and add the single source file you wish to debug by right-clicking on the project browser sources folder. It takes mere seconds.

Resources