Facing an issue int the terminal of VS code - c

I am very new to coding, it being only 3 weeks until I have started to learn to code. I write very small codes as of now (like only 20-30 lines, maximum 44) Whenever I write a code, then run it, as you might know, that if I have written a code for finding if the number is prime or not, I have to write in the terminal, ./prime and then press enter, then input a number.
But, when I do that in my VS code software, when I write, ./prime and then press enter, it shows:
bash: ./prime: No such file or directory.
I observed that my teacher is using that terminal in git bash, so I installed GitHub and used git bash for it, still, this problem was occurring. My brother predicted that you might not be saving the file, do that and then play it on the terminal. I even did that, but still, it was happening. And this is happening with every code I am typing, all the 44 code files.
Idk if this is happening because I have missed to download a particular file of mingw, or is there a different method to do that, for windows(my OS), because my teacher uses mac

You need to compile your code before you execute.
In terminal run command gcc prime.c -o prime and then you are good to go with ./prime

Related

Creating an executable file at Visual Studio Code

I am relatively new in programming using the C-language. So to lay it all out, I am still kind of clueless of what is happening. Now, may I ask why I can't seem to create an exe file and run the code?
Actually, the first time I tried executing it, it worked. However, to make sure that it is working, I repeated it and then it didn't work anymore.
To make things clearer:
I use Mac
Mac OS Big Sur
In this particular case, gcc is the compiler
I also tried using Code::Blocks also prior to this; however, I have similar issues -- after I built and ran my first "hello world" program, it didn't run the same program anymore after it. I also tried reinstalling it, but it still has the same issues.
I'm really frustrated that this is happening because I cannot move on to the next lessons in my class. :(
Thank you very much! I hope someone would help a newbie here. :))
Gcc by default names executables a.out. So you can check if that file has been created by running ls a.out and looking through the results.
If it has been made, you can run it from the command line with ./a.out.
If you want to name the executables something else, then when calling gcc, add the flag -o followed by the name you want. E.g. if you want filename.c to compile to filename.exe, then you would write gcc -o filename.exe filename.c. Then you can run it from the command line with ./filename.exe. I think if you give it the .exe file extension you should also be able to run it by clicking it in the Windows file explorer.

How do you debug C code in visual studio code

If I am to compile my code in the terminal, I would do:
cc -std=c99 -Wall -Werror ....
If I'm to run my code in the terminal I would do:
./testprogram text.txt 1000 1000
The numbers and the text file is significant to the program.
Hopefully that gives some insight into the version of c I'm using and how to execute my program. Now: how do you debug this with visual studio code? I have installed the c/c++ extension.
Every time I try to start debug it asks me to chose between two environments:
c++ (GDB/LLDB)
c++ (windows).
My first problem is that non of those two options are just plain c, but maybe I just don't know better and there isn't much difference. Never the less, I gamble on one of the environment, usually the first one, then I'm asked to pick between:
two gcc-9 build and debug active file,
one gcc build and debug active file,
and defult configuration.
I usually pick the defult config one and that leads me to the launch.json page. I put in my program directory: "${workspaceFolder}/testprogram.c" and error.. :
Unable to start debugging. Launch options string provided by the project system is invalid. Unable to determine path to debugger. Please specify the "MIDebuggerPath" option.
Nothing I've tried so far or any googling have helped so hopefully someone with a lot of experience would be able to help out here. Thanks in advance.

Unable to run C programs using any compiler

I had to write code in C and run it for an assignment. Since this is the first time that I'm using C, I downloaded MinGW as a compiler and Code Blocks as an IDE. I had no problem compiling the code given by my professor but it never runs (this is a simulation for an M/M/1 queue). When I say it never runs, I mean that a command prompt like window pops up and nothing happens after that. Every time I close that window and try to compile the SAME program again, I get an error that says that permission to access the file has been denied.
I then deleted Code Blocks and tried running the program through command prompt but I have the same problem. I've now tried doing it using LCC-Win but nothing has changed. Another weird thing that happens when I run any program is that three instances of the .exe file of that particular program are in my processes under task manager. I then need to restart my computer to try compiling that same program.
I even tried running a simple Hello World program and I have the same problem!
I am currently using a Windows 7 32-bit system.
Any help would be greatly appreciated!

Debugging using input file OS X

I searched for a solution to my problem already in Google and here in stack overflow.
I didn't found an understandable and precise solution for my problem:
I've written a program that maintains an inventory.
It compiled without warnings or errors and it works quite well when I type in commands by hand. When I'm running the program with an input file with much more parts I get a segmentation fault 11.
Now I want to debug my program but don't know how to do this using input files.
I already did some debugging via the CodeBlocks IDE. Didn't find a option for this.
I used malloc and realloc functions in my program and think the error happened there because I never used it before.
Could you please help me in following ways:
I need a debugger that can debug while the program runs with an input file.
The debugger must be able to check for memory leaks or things like this.
Thanks
Armin
Debugging with command line input vs. Debugging with a input file is the totally same.
You must understand this.
When you start debugging session in the IDE, it is by default 'no input' mode (no input file).
But you can specify startup conditions for the program, including working directory, command line arguments, etc.
By using these options, you can run the debugging session exactly same as user running the program with input files.

cygwin terminal converts my letters to numbers

I recently coded a '.C' file with scanf in order to take keyboard inputs. To my great surprise, the cygwin terminal converted all the letters I typed to numbers. My program ran properly though. The cygwin terminal just didn't show the correct input that I typed. It even converted some non-alphabet keys into symbols.
If I pressed the same alphabet key multiple times, the numbers (showing up in the cygwin terminal) would change each time I pressed the key. I talked to my computer science professor about this and he didn't know how to fix it.
Another thing to be noted is that my professor was able to use the cygwin executable(?) via the command terminal in order to run my '.C' file. When he ran the program in this way, the command terminal was able to accept letters.
I got the cygwin installation package from the GATech mirror website and this is the first error I've come across using cygwin.
I am using windows XP and netbeans to run the '.C' ;
check your .(bash)rc settings, try alternativ "consoles" (mintty, xterm,...)
...was able to use the cygwin executable...
they are still windows .exe files

Resources