Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
JensenEx

Trouble Running C in VS Code

Recommended Posts

Posted · Original PosterOP

Hi beautiful people !

Alright actually I'm running out of time to complete my stuff so Im gonna get to the point here. Im an Engineering student, learning C programming for a subject. Long story short, I have VS Code and I wish to run my C code there, so I went on and google search for solutions and found out a few that seems easy for me to understand. So I went on and try one if it, which is installing the C/C++  Extension for VS Code, I saw on Youtube video that once you install it and re-launch your VS Code, you're good to go. But no it doesnt work for me, when I tried to Run my code (without Debugging), it gave me 2 Environment option to choose from, one is "C/C++ (GDB/LLDB" and the other one is "C/C++ (Windows). So anyways either one of them gave me the same result, which is putting me to a Settings.json file and I have no idea what to do there, it doesn't run my code, it is just there. 

Is there anything I have to write in the Settings.json file in order to run my C code ? I have attached screenshots of the extension I installed as well as the settings.json file. 

Any help would be appreciated, Thank You !

Regards,
Jen.

C C++ extension.png

my VS code and C code (2).png

settings.json page.png

Link to post
Share on other sites

Since the main function is of type int you should return an int at the end - just add

return 0;

below the final print statement. Without this it shouldn't compile no matter what.

 

As for running it in vscode, I just tried it with the "C/C++", "C/C++ Compile Run" and "Code Runner" plugins and it just worked when I clicked on the "run" button in the top right, no need for restarting or anything else.


...is there a question here? 🤔

sudo chmod -R 000 /*

What is scaling and how does it work? Asus PB287Q unboxing! Console alternatives :D Watch Netflix with Kodi on Arch Linux Sharing folders over the internet using SSH Beginner's Guide To LTT (by iamdarkyoshi)

Sauron'stm Product Scores:

Spoiler

Just a list of my personal scores for some products, in no particular order, with brief comments. I just got the idea to do them so they aren't many for now :)

Don't take these as complete reviews or final truths - they are just my personal impressions on products I may or may not have used, summed up in a couple of sentences and a rough score. All scores take into account the unit's price and time of release, heavily so, therefore don't expect absolute performance to be reflected here.

 

-Lenovo Thinkpad X220 - [8/10]

Spoiler

A durable and reliable machine that is relatively lightweight, has all the hardware it needs to never feel sluggish and has a great IPS matte screen. Downsides are mostly due to its age, most notably the screen resolution of 1366x768 and usb 2.0 ports.

 

-Apple Macbook (2015) - [Garbage -/10]

Spoiler

From my perspective, this product has no redeeming factors given its price and the competition. It is underpowered, overpriced, impractical due to its single port and is made redundant even by Apple's own iPad pro line.

 

-OnePlus X - [7/10]

Spoiler

A good phone for the price. It does everything I (and most people) need without being sluggish and has no particularly bad flaws. The lack of recent software updates and relatively barebones feature kit (most notably the lack of 5GHz wifi, biometric sensors and backlight for the capacitive buttons) prevent it from being exceptional.

 

-Microsoft Surface Book 2 - [Garbage - -/10]

Spoiler

Overpriced and rushed, offers nothing notable compared to the competition, doesn't come with an adequate charger despite the premium price. Worse than the Macbook for not even offering the small plus sides of having macOS. Buy a Razer Blade if you want high performance in a (relatively) light package.

 

-Intel Core i7 2600/k - [9/10]

Spoiler

Quite possibly Intel's best product launch ever. It had all the bleeding edge features of the time, it came with a very significant performance improvement over its predecessor and it had a soldered heatspreader, allowing for efficient cooling and great overclocking. Even the "locked" version could be overclocked through the multiplier within (quite reasonable) limits.

 

-Apple iPad Pro - [5/10]

Spoiler

A pretty good product, sunk by its price (plus the extra cost of the physical keyboard and the pencil). Buy it if you don't mind the Apple tax and are looking for a very light office machine with an excellent digitizer. Particularly good for rich students. Bad for cheap tinkerers like myself.

 

 

Link to post
Share on other sites
31 minutes ago, Sauron said:

Since the main function is of type int you should return an int at the end - just add


return 0;

below the final print statement. Without this it shouldn't compile no matter what.

 

main doesn't require you to explicitly return something, it will compile without it :)

edit: could it be that I'm using the gcc compiler? this one doesn't require it

 

@JensenEx I take it that you want to do it automatically, I honestly don't remember how to do it since I haven't used VSCode in a long time, if you wanna do it manually: gcc -o outputFile sourceFile.c  :D

Link to post
Share on other sites
1 minute ago, Hi P said:

main doesn't require you to explicitly return something, it will compile without it :)

Weird, I thought I remembered it not working... I guess it's some compiler magic. Still I'd say it's good practice to explicitly return 0.


...is there a question here? 🤔

sudo chmod -R 000 /*

What is scaling and how does it work? Asus PB287Q unboxing! Console alternatives :D Watch Netflix with Kodi on Arch Linux Sharing folders over the internet using SSH Beginner's Guide To LTT (by iamdarkyoshi)

Sauron'stm Product Scores:

Spoiler

Just a list of my personal scores for some products, in no particular order, with brief comments. I just got the idea to do them so they aren't many for now :)

Don't take these as complete reviews or final truths - they are just my personal impressions on products I may or may not have used, summed up in a couple of sentences and a rough score. All scores take into account the unit's price and time of release, heavily so, therefore don't expect absolute performance to be reflected here.

 

-Lenovo Thinkpad X220 - [8/10]

Spoiler

A durable and reliable machine that is relatively lightweight, has all the hardware it needs to never feel sluggish and has a great IPS matte screen. Downsides are mostly due to its age, most notably the screen resolution of 1366x768 and usb 2.0 ports.

 

-Apple Macbook (2015) - [Garbage -/10]

Spoiler

From my perspective, this product has no redeeming factors given its price and the competition. It is underpowered, overpriced, impractical due to its single port and is made redundant even by Apple's own iPad pro line.

 

-OnePlus X - [7/10]

Spoiler

A good phone for the price. It does everything I (and most people) need without being sluggish and has no particularly bad flaws. The lack of recent software updates and relatively barebones feature kit (most notably the lack of 5GHz wifi, biometric sensors and backlight for the capacitive buttons) prevent it from being exceptional.

 

-Microsoft Surface Book 2 - [Garbage - -/10]

Spoiler

Overpriced and rushed, offers nothing notable compared to the competition, doesn't come with an adequate charger despite the premium price. Worse than the Macbook for not even offering the small plus sides of having macOS. Buy a Razer Blade if you want high performance in a (relatively) light package.

 

-Intel Core i7 2600/k - [9/10]

Spoiler

Quite possibly Intel's best product launch ever. It had all the bleeding edge features of the time, it came with a very significant performance improvement over its predecessor and it had a soldered heatspreader, allowing for efficient cooling and great overclocking. Even the "locked" version could be overclocked through the multiplier within (quite reasonable) limits.

 

-Apple iPad Pro - [5/10]

Spoiler

A pretty good product, sunk by its price (plus the extra cost of the physical keyboard and the pencil). Buy it if you don't mind the Apple tax and are looking for a very light office machine with an excellent digitizer. Particularly good for rich students. Bad for cheap tinkerers like myself.

 

 

Link to post
Share on other sites
3 minutes ago, Sauron said:

Weird, I thought I remembered it not working... I guess it's some compiler magic. Still I'd say it's good practice to explicitly return 0.

Yea it's the gcc compiler, definitely good practice to add it :D

 

39 minutes ago, Sauron said:

As for running it in vscode, I just tried it with the "C/C++", "C/C++ Compile Run" and "Code Runner" plugins and it just worked when I clicked on the "run" button in the top right, no need for restarting or anything else.

I followed this answer and worked like a charm :)

Link to post
Share on other sites
Posted · Original PosterOP
2 hours ago, Sauron said:

Since the main function is of type int you should return an int at the end - just add


return 0;

below the final print statement. Without this it shouldn't compile no matter what.

 

As for running it in vscode, I just tried it with the "C/C++", "C/C++ Compile Run" and "Code Runner" plugins and it just worked when I clicked on the "run" button in the top right, no need for restarting or anything else.

Hi there, I just tried downloading "Code Runner" and it works. But um, my code requires input, it requires the cmd to pop up so that I can give input and execute the code after that. What do I need in order to run it that way ? With Code Runner it just keeps saying that my code is running and there's nothing for me to be able to interact with. Wasn't expecting this to happen..

Link to post
Share on other sites
13 minutes ago, JensenEx said:

Hi there, I just tried downloading "Code Runner" and it works. But um, my code requires input, it requires the cmd to pop up so that I can give input and execute the code after that. What do I need in order to run it that way ? With Code Runner it just keeps saying that my code is running and there's nothing for me to be able to interact with. Wasn't expecting this to happen..

Open the extension settings and tick the box that says "Run in Terminal"


...is there a question here? 🤔

sudo chmod -R 000 /*

What is scaling and how does it work? Asus PB287Q unboxing! Console alternatives :D Watch Netflix with Kodi on Arch Linux Sharing folders over the internet using SSH Beginner's Guide To LTT (by iamdarkyoshi)

Sauron'stm Product Scores:

Spoiler

Just a list of my personal scores for some products, in no particular order, with brief comments. I just got the idea to do them so they aren't many for now :)

Don't take these as complete reviews or final truths - they are just my personal impressions on products I may or may not have used, summed up in a couple of sentences and a rough score. All scores take into account the unit's price and time of release, heavily so, therefore don't expect absolute performance to be reflected here.

 

-Lenovo Thinkpad X220 - [8/10]

Spoiler

A durable and reliable machine that is relatively lightweight, has all the hardware it needs to never feel sluggish and has a great IPS matte screen. Downsides are mostly due to its age, most notably the screen resolution of 1366x768 and usb 2.0 ports.

 

-Apple Macbook (2015) - [Garbage -/10]

Spoiler

From my perspective, this product has no redeeming factors given its price and the competition. It is underpowered, overpriced, impractical due to its single port and is made redundant even by Apple's own iPad pro line.

 

-OnePlus X - [7/10]

Spoiler

A good phone for the price. It does everything I (and most people) need without being sluggish and has no particularly bad flaws. The lack of recent software updates and relatively barebones feature kit (most notably the lack of 5GHz wifi, biometric sensors and backlight for the capacitive buttons) prevent it from being exceptional.

 

-Microsoft Surface Book 2 - [Garbage - -/10]

Spoiler

Overpriced and rushed, offers nothing notable compared to the competition, doesn't come with an adequate charger despite the premium price. Worse than the Macbook for not even offering the small plus sides of having macOS. Buy a Razer Blade if you want high performance in a (relatively) light package.

 

-Intel Core i7 2600/k - [9/10]

Spoiler

Quite possibly Intel's best product launch ever. It had all the bleeding edge features of the time, it came with a very significant performance improvement over its predecessor and it had a soldered heatspreader, allowing for efficient cooling and great overclocking. Even the "locked" version could be overclocked through the multiplier within (quite reasonable) limits.

 

-Apple iPad Pro - [5/10]

Spoiler

A pretty good product, sunk by its price (plus the extra cost of the physical keyboard and the pencil). Buy it if you don't mind the Apple tax and are looking for a very light office machine with an excellent digitizer. Particularly good for rich students. Bad for cheap tinkerers like myself.

 

 

Link to post
Share on other sites
3 hours ago, Sauron said:

Weird, I thought I remembered it not working... I guess it's some compiler magic. Still I'd say it's good practice to explicitly return 0.

I think it is compiler magic as I know for a fact that I need a return statement in VC++. GCC might imply a default return statement in a program which doesnt have one.


CPU: Intel i7 - 5820k @ 4.5GHz, Cooler: Corsair H80i, Motherboard: MSI X99S Gaming 7, RAM: Corsair Vengeance LPX 32GB DDR4 2666MHz CL16,

GPU: ASUS GTX 980 Strix, Case: Corsair 900D, PSU: Corsair AX860i 860W, Keyboard: Logitech G19, Mouse: Corsair M95, Storage: Intel 730 Series 480GB SSD, WD 1.5TB Black

Display: BenQ XL2730Z 2560x1440 144Hz

Link to post
Share on other sites
Posted · Original PosterOP
1 hour ago, Sauron said:

Open the extension settings and tick the box that says "Run in Terminal"

I got it !! Thank you so much for everyone's help !!!!

Link to post
Share on other sites
48 minutes ago, trag1c said:

I think it is compiler magic as I know for a fact that I need a return statement in VC++. GCC might imply a default return statement in a program which doesnt have one.

 

4 hours ago, Sauron said:

Weird, I thought I remembered it not working... I guess it's some compiler magic. Still I'd say it's good practice to explicitly return 0.

Agreed, it's always good practice to put the return 0.

 

It is not compiler magic though, it is part of the ISO standard (well at least the older standards...I am outdated on my CPP standards though, so maybe they adapted it in newer versions)

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf (Section 3.6.1 Point 5)

Quote

[...] If control reaches the endofmainwithout encountering areturnstatement, the effect is that of executingreturn 0;

Either way, yes you are right explicitly having a return 0 is the best practice


3735928559 - Beware of the dead beef

Link to post
Share on other sites

Technically, int main(... something ...) is not always mandatory.

 

In a freestanding environment (in which C program execution may take place without any benefit of an operating system), the name and type of the function called at program startup are implementation-defined.

 

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2310.pdf

 

Example: The Windows API really would like you to have a function named WinMain() instead.


Write in C.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×