pretzlstyle
pretzlstyle

Reputation: 2962

How to run C code from terminal?

I am working on an assignment for class, and we are to work off of a class server where the code files are held.

I have copied the files to my home directory, and have been editing with vim (since my instructor for some reason prefers it to emacs).

But how do I actually test my code? the make file is provided, and when I type make test.c, I get back make: Nothing to be done for test.c. I don't understand why this is happening, because I have a print statement as the first line in main. Shouldn't that at least run? Also, how do I pass arguments to the main function test.c while using make??

As a side question, this server doesn't have gdb either, for some reason. I'm sure there is an alternative installed, I just don't know what it would be called to try and see if it's here.

Upvotes: 0

Views: 25189

Answers (4)

Shishir Jha
Shishir Jha

Reputation: 1

Simply save your code and then open the command prompt and write these command

  1. gcc .\fileName.c and press Enter
  2. Simply press a + tab and then print Enter and there you go.

Upvotes: 0

Box Box Box Box
Box Box Box Box

Reputation: 5241

I think you need some basic knowledge in make. You should read some basic books on makefile and actually try it out. If you just try to stick concepts to your mind, but never actually try it out, you will never get it.

Check out this question. It asks for good tutorials on GNU Make. Also, so that you can go directly to the links, this and this are links mentioned in the main answers.

Upvotes: 0

Keith Thompson
Keith Thompson

Reputation: 263237

The argument to make is usually the thing you want it to create. Since test.c already exists, make test.c doesn't do anything. make test should compile test.c to create test. make with no arguments uses a default target specified in the Makefile; in your case it's probably the same as make test.

The make command doesn't run your program; it creates an executable that you can then run.

Once you've typed make or make test, you should be able to execute your program by typing

./test

The ./ is important; without it, you'll probably invoke the shell's built-in test command, which is not what you want.

Upvotes: 2

Justlike
Justlike

Reputation: 1504

Maybe what u need is only this build command:

gcc test.c -o test

Then:

./test

Have a try. ^_^

Upvotes: 1

Related Questions