VSCode issues when running a C file and displaying output - c

I'm trying to run C programs/files from VSCode. I've followed a guide to setting up the gcc for VSCode to use, and it "mostly" works. However, when I run a file, it only outputs to the debug console, which is rather messy. I would prefer if it only output to the "output" window.
If I click on the output window and then try to run the file, I get this error.
This is what my tasks.json file looks like, where I've tried to change build from cppbuild to shell, as well as removing the "file" lines that I saw recommended on other threads, which didn't solve my issue.
Also notice how in the drop down menu for my panel, I don't have a "Code" option that I see in other people's VSCode
TLDR: I want VSCode to display the output of a C file into the Output window, not the debug console. I also want to understand why I am given the "Cannot build and debug because the active file is not a C or C++ source file" error. MinGW has been downloaded and GCC has been set up properly, AFAIK.

Have you installed "Code Runner" extension?

Related

How to remove the file path from terminal while running a code in visual studio code (mac os )?

How to remove the file path from terminal while running a code in visual studio code ?
Im using visual studio code with CodeRunner extension in Mac air M1.
I’ve tried to play with the terminal settings and I couldn't find the one that remove this.
I want that remove the part I marked in red, when i running my program.
Welcome to StackOverflow! 👋
This line is terminal command to compile source code file and run executable.
Soooo, I am not sure if you can remove this. What you can do is write bash script and give your file as an input, but anyway you will pass your file as an argument. What you can do is configure build task and run your executable file from terminal, but I'm not sure would you like this way or not.
As others mentioned this is the gcc (your c compiler) build command. Reason: You build and run your program. This should vanish when you explicit build. And then just run your program without build. Or open Terminal and run your binary with:
cd /Users/metanpolik/Desktop/VisualProjects
./heyc2
But like #UnholySheep wrote, what is the problem? It's just during developing with vs code and should not be a problem.

Confing launch.json in Vscode to fire up internal gdb

I'm trying to configure launch.json in vscode in order to be able to debug my program inside the editor. I' m facing 126. The vscode documentation explains here, that I need to create the 10-ptrace.confe inside /etc/sysctl.d/ and append this into it :
kernel.yama.ptrace_scope = 0
I'm getting into all of these because I don't want to run vscode as root for a simple debug session.
The problem is that the file already exists and I don't have permission to write on it, even after using:
sudo chmod +w 10-ptrace.conf
Moreover, these value that I was supposed to write in the file is set to 1 instead of 0.
How can I overcome those difficulties and debug my C program?
Is there any better way to start the debug session that I should be trying instead?
Alternative question:
If I run gdb via terminal, how can I plot the addresses to find the one that my program is segfaulting ? Should I be using a disassembler or something else? I'm currently using radare, but my prior experience is with QtSpim. Do you have any suggestions ?
I appreciate any kind of help.
gdb generates assembly code that corresponds directly to your source code "optimized code"
i can suggest to try "hex editor" and edit your binary code file it's available on windows and linux.
hope that could help you

Equivalent of 'make' command for CodeBlocks?

I am using Codeblocks in Windows 10. Earlier I used to compile only 1 file, so I would just press the 'Build' and 'Run' button on codeblocks.
But, this time there are separate files I need to compile separately (to .o format) and then link to form a single executable file which I need to run. How can I do this in CODEBLOCKS? (In UNIX/LINUX systems, I know this is the 'make' command; but I don't know how to do it here?)
Can anyone help me? I tried reading some help pages on CodeBlocks on the internet, but they were so complicated, I gave up.
make isn't a compiler, and neither is CodeBlocks. make is just a command that runs other commands from a Makefile. The actual command that gets run is something along the lines of gcc a.cpp b.cpp, and it's the same command (or similar enough) that gets run when you build inside CodeBlocks. CodeBlocks should automatically build and link all of the source files that you add to your project. If you aren't seeing this happening, make sure you add them to the project inside of CodeBlocks and don't just put the files in the directory.

Eclipse Neon on Linux: no console for C/C++ programs

With Eclipse 4.6.2 on Ubuntu 16.04.1 I'm having trouble getting the console to work with C/C++ programs. When I run my program from a shell, it produces output on stdout and stderr and accepts input from stdin. However, when I "Run as C/C++ Appplication" in Eclipse, the console doesn't seem to work — standard output and error never appear, and there's no place to supply input.
Has anyone seen this? Any idea why it's happening? It's worth noting that Java applications that use the console work fine, so this is specific to C/C++ somehow.
Source code:
Compiler settings:
Run configuration:
There may be so many reasons for your problem but i will give you some to do list in order to solve your problem.
1) Please build your C/C++ code before you run it. You can do it via Ctrl+B button combination or by clicking on menu.
2) Be sure that you have one main function in your current project and there is no debugger errors.
3) The reason why your code is working on shell but not in Eclipse may be that your Eclipse might not know your compiler's name or path. You can check this case by following this path :
Click File on menu -> Click properties -> Expand "C/C++ Build" -> Click on "Settings".
In the opening screen you have to see gcc/g++ compiler is set properly and Command line pattern is true and working on Eclipse.
If you give more detail about your Eclipse version or some screenshots, we can help you more precisely.
Also i reccomend using "Eclipse IDE for C/C++ Developers" version of eclipse in this link : http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/keplersr2
When you install this version, probably you will not need to set so many settings to work on your projects.
Edit: That's the example usage of fputs.
#include <stdio.h>
int main ()
{
FILE *fp;
fp = fopen("file.txt", "w+");
fputs("This is c programming.", fp);
fputs("This is a system programming language.", fp);
fclose(fp);
return(0);
}

how do I get my eclipse CPP lunar to show ouput?

I just installed Eclipse CPP lunar for my windows 64, and I ran a couple of C code (not c++), but for some reason I can get to the console to show any output, I did the build PATH in the environment part in my properties, but still can't get anything to show. I run my C code in cmd, and everything was perfect! what should I do? do I need to add new flags, it seems the code can run well just no ouput.
update: I watched a video on youtube, and I run some c++ code and the output console is perfect for some reason, just C code I can't get any output. did I built the path wrong?
According to http://www.mochaz.com/2012/03/solution-for-no-console-output-in.html there is a workaround, where you have to add the path of the MinGW compiler (which you most likely use) to the Environment variable of your project (project specific settings).
Goto Project->Properties->Run/Debug Settings, choose the .exe file and press Edit
In the Environment tag, press New, and set it as: Name: PATH, Value: C:\MinGW\bin

Resources