How to execute a C program in VS Code - c

Okay, I am an idiot and I cannot figure out how to compile and run C program in VS Code. How should I do it? I typed in the code itself, so what is next in order for me to see the output in terminal? Thanks for accepting my stupid

link your compiler to vs code. if you are using c, it should be gcc or some other fork. to use the compiler just open the terminal, go to gcc or what your compiler name is, and then run it in terminal(if you right click on code)

Related

IOCCC Program compiling errors

code: http://www.ioccc.org/1988/phillipps.c
How do i run this on Coderunner?
I've encountered some compiling problems that i can't solve after searching on the internet.Can someone help me out?
If I am not being informative enough, i'm sorry, but please tell me how i can do better at asking these tech questions.
compiling errors below(i use coderunner)
The program is written in an old dialect of C and is relying on some features now considered broken. Clang (the compiler in question) is not happy about the third argument of main and I don't think you can convince it to accept that.
You can either install gcc, that compiler will accept the code with just warnings. But I don't think coderunner has gcc integration.
Or you can manually unscrew the objectionable bit of the code.
Replace all instances of the word main with mayn in the code and add this bit of code to the beginning of the file:
main() {
mayn(1,0,0);
}
Now you can enjoy the program under clang/coderunner as well.

Cannot compile C programs on CodeBlocks: Undefined reference to 'WinMain#16'

I'm new to C and I'm trying to compile a HelloWorld program. I'm using GNU GCC 4.9.2. I've looked online for many solutions but none of them worked: Every time I compile the program, it hits me with this error:
"Undefined reference to 'WinMain#16'"
Please bear in mind that I HAVE configured the project as a console project, not a windows project and that I have written the main function correctly.
Here's the code:
#include <stdio.h>
int main()
{
printf("Hello world!\n");
return 0;
}
Finally, note that I can successfully compile, build, and run C++ programs with code blocks. For some reason, I can't do the same for C. Additionally, I tried compiling the source file from the command line and the issue still persisted.
Compilation lines:
I solved the problem and I don't know how. I changed the C debugger from gcc to gnu, it gave me a different error. I then changed it back to gcc and it started working randomly. I've been trying to solve this problem for literally 6 hours. Then I try some random nonsense and guess what? it works.
I hate software development.
I love software development.

System calls not working in Atmel AVR Studio (with ASF)

I am not getting answers on the AVR Freaks forum and wonder if someone here could help me.
The answer might lie in this SO question, but I am not sure why it would be necessary.
Basically, I have my fist ever Atmel project (AVR studio 6, UC3 processor). The code compiles and links and I can load it to the Atmel board and step through in the debugger.
However, when I try to step over (or run until a breakpoint on the line after) a (valid) call to sprintf(), malloc() or memcpy() (there may be more, which I have not yet discovered), the IDE never returns to the next line of my code, just seeming to hang, or run forever.
[Note] Compiler optimization is off
Do I need to set some linker options (e.g link static (which I tried & it didn't help)? Or build with some library?
What confuses me is that the code compilers and links - what is being linked when I call these standard functions? If I need something else I would expect a compiler or linker error, but get none - so why won't my code run?
Sorry for such a stupid n00nb question, but it is my first micro-controller project.
I discovered that the CPU on my board is an Engineering Sample and not supported by Atmel Studio without a new io.h file.
I sort of figured that out from this question: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=106652
Sorry to have troubled you.
what is being linked when I call these standard functions?
The AVR-libc, the implementation of the C standard library ported to the AVR platform.
so why won't my code run?
Compiler errors and runtime errors are not even related. Both of these lines are valid C and they compile, however, on most systems, I'd expect them to dump core:
int x = 1 / 0;
*(int *)0 = 41;
So it might be either:
a bug in the standard library (very unlikely), or
a bug in the online debugger (very unlikely), or
maybe you just expect something that is not supposed to happen?
Instead of trying to step over, what happens if you set a breakpoint at next line after the line you want to step over?
Also, does the operation change if you turn off compiler optimization?

Running the Hello World C code from command prompt?

I have written a very simple C program to print "Hello World" in my Notepad text editor and saved it as test1.exe. I opened my cmd and ran the file test.exe and the received error is as follows:
The NTVDM CPU has encountered an Illegeal instruction. CS:0607
IP:0103 OP:63 6c 75 64 65 Choose 'Close' to terminate the application.
You need to save the file as test.c and then compile it to test.exe. The exact details of how you compile it will depend on what C compiler you have installed, but for cygwin or MinGW it would be:
$ gcc -Wall test.c -o test.exe
If you don't have a compiler installed yet and just want to quickly try running a small C program then a further alternative is to use a site such as codepad.org or ideone.com where you can type (or paste) your code and run it online.
A few things to help you learn C in an easier manner:
First, you say you wrote it in Notepad. Bad choice for learning C. Notepad does not support Syntax highlighting.
Second, C needs to be compiled, on windows you have a few choice for compiler, the first would be MinGW which is Free.
Third, and IDE that is MinGW aware and C syntax aware is also needed. Geany is simple enough but is very smart and full of sweets.
Finally, see the tutorial here, how to get them all working: geany+mingw on windows.
One more thing, totally unrelated to C, or maybe it does.
I bluntly assume that C is your first programming experience, or that you are still doing first steps in programming.
C as a first language is VERY BAD. It is not forgiving, and most compilers pass things, but the code will crash, not letting you know what you did wrong.
Consider learing other languages first, a few good choices would be:
Python
Lua
Ruby
If you need a compiler and environment for C, I'd go with Visual Studio Express instead of the other suggestions. It's much more comfortable and offers a fuller Windowsy feel. And it's also free.

Using XCode to learn C with K&R, but getting too many errors

I'm want to learn C programming with K&R using XCode, but I can't even get the Hello World to work right - it's giving me errors it shouldn't, I guess because it's being very technical. Can I get XCode to relax on requirements? Would greatly appreciate some advice! Thanks.
Xcode Bah! Just compile from the command line:
gcc myfile.c -o myfile
You don't need Xcode, but if you want to ... Xcode has hello world built in. Make a new project "Command Line Utility", "Standard Tool", give it a name, have a look in "Source", and you'll see the Hello World program:
#include <stdio.h>
int main (int argc, const char * argv[]) {
// insert code here...
printf("Hello, World!\n");
return 0;
}
Click "Build and Run" and it goes, you see:
Running…
Hello, World!
Debugger stopped.
Program exited with status value:0.
I will agree with ergosys above. Xcode is realistically made for Objective-C coding, and even its "Command Line Utility" template is sheer overkill. Anything in K&R will compile flawlessly with
gcc -Wall filename.c
except maybe some of the more advanced stuff. K&R doesn't go into object compiling or linking extensively, since it's only meant to teach you the language. Grasp compilation though, and learning C will be much easier. I much prefer using Makefile's or gcc/g++ than IDE's like Xcode or Eclipse.
I'm gonna assume that XCode is demanding Ansi Standard C, while you are using an early edition of the K&R book, whch still uses the old style.
Unless you are doing this just so you can interprete some ancient C code, don't bother with the old style. Use the Ansi Standard syntax.
Honestly, XCode is way more than you need if using K&R. K&R is about basics, XCode is about making you pull your hair out.
I actually prefer to use the command line instead of an IDE on the Mac.
At least for K&R, using the command line is the way you want to go. Try:
gcc -o outputfile code.c
If you want to get into iPhone/iPod or Cocoa applications, then use Xcode. But more times than most, XCode is overkill and will probably just slow you down.
As I said in my comment, you shouldn't see an error from Xcode with the hello world program from K&R. You might be seeing some warnings, or you have mistyped something. Remember to select the correct language for compiling (you want C, of course).
Can I get XCode to relax on requirements?
In general, you want the compiler to be able to warn you for things that it thinks are not "right". In some cases, the warnings are harmless, and can be turned off, but in most of the cases, the warnings expose issues with your program. I like compiling my code with the maximum warnings enabled for example, because it saves me a lot of time later.
If you are getting errors, you should post (copy-paste) your code here.
Finally, look at the errata page for K&R. It has some bug fixes or corrections, but nothing for hello world.
(It could be that you're using the first edition of the book, in which case you shouldn't use that book to learn C.)

Resources