LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-21-2004, 02:13 PM   #1
killos
LQ Newbie
 
Registered: Dec 2004
Posts: 14

Rep: Reputation: 0
HELP!! Compiling on C


Hello, people, I am new to the site etc etc.....

I just have a quick question regarding compiling of C, I believe it simple (well not to me), and any help would be much appreciated.

Basically I am a beginner at C programming language and I am having difficult at compiling any code.

At the moment I placed the following code onto notepad and saved it as samp.c:

#include <stdio.h>

int main()
{
printf("This is output from my first program!\n");
return 0;
}


The problems is when I try to compile the code whether through cc or gcc, by doing gcc samp.c –o samp.exe I always get the following response:

“No such file or directory”

How do I overcome this problem ?? (also on my computer I have several dives)
 
Old 12-21-2004, 02:29 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Make sure your current working directory is the same directory where you have your samp.c file saved...
 
Old 12-21-2004, 03:15 PM   #3
killos
LQ Newbie
 
Registered: Dec 2004
Posts: 14

Original Poster
Rep: Reputation: 0
Thank You for the response!

my working directory probably my C drive, the files in my H drive I would I change it ??
 
Old 12-21-2004, 03:33 PM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Just save your samp.c in something like c:\

Then go to Start -> Run, type cmd and press ENTER.

Then type c:\, press ENTER.

Then compile your program with gcc.

It doesn't have to be c:\, but you have to navigate to the directory. You can't just try to compile samp.c from anywhere. What if you have more than one file called samp.c on your harddrive? That's why the directory structure exists in the first place. Learn it, use it, own it.
 
Old 12-21-2004, 04:51 PM   #5
bm17
Member
 
Registered: Sep 2004
Location: Santa Cruz, CA, USA
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
Re: HELP!! Compiling on C

Quote:
Originally posted by killos

printf("This is output from my first program!\n");
The ANSI standard requires that the first C program that you write should print out "Hello, world!\n".

Typical rookie mistake.

-b
 
Old 12-22-2004, 09:11 AM   #6
killos
LQ Newbie
 
Registered: Dec 2004
Posts: 14

Original Poster
Rep: Reputation: 0
mjrich =>

Quote:
You definitely do have gcc installed, and within your path ? (What happens when you just type gcc <enter> into a shell ?)
when I do that it's says 'No Input file'


itsme86 - the files saved within my H drive, I've tried running it, by stating the complete address of the file, for example gcc h:\samp -o samp.exe, but I still get the same problem

bm17 - I try what you said but I don't see how it's going to make much of a difference
 
Old 12-22-2004, 10:51 AM   #7
bm17
Member
 
Registered: Sep 2004
Location: Santa Cruz, CA, USA
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
I was just joking about Hello World.

How did you install the compiler? Are you using Cygwin? If so, I think you need to be running in some sort of shell enviroment for unix commands to work. The README file or googling for "cygwin" should point you in the right direction.
 
Old 12-22-2004, 11:03 AM   #8
killos
LQ Newbie
 
Registered: Dec 2004
Posts: 14

Original Poster
Rep: Reputation: 0
ha!!

what it is, that I am using the C programming through windows on a shared serve, I have al the info. to create and compile programs.

but as a beginner I can't even compile this simple one and move on to the more complex, but I know it has something to do with the directory.

That why I'm wondering if it is possible to change the default directory in C ??? if you can how ??
 
Old 12-22-2004, 11:29 AM   #9
bm17
Member
 
Registered: Sep 2004
Location: Santa Cruz, CA, USA
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
gcc is a command-line program. You need to invoke it from the shell, or DOS prompt. Depending on what flavor of gcc it is, it will use certain environment variables to locate the files it needs in order to operate. For instance, it needs to know where to find the include files. You need to find out what kind of gcc installation this is.

Running raw gcc is an advanced issue if you are used to Windows packaged GUI applications. Perhaps you would be better served with a copy of Visual Studio. Failing that, find out who installed gcc, ask them where it came from, and then read the instructions for using it. I admit that this is a complicated problem, but gcc simply wasn't intended to be used directly from a windowed environment without running some sort of setup script first.
 
Old 12-22-2004, 11:52 AM   #10
killos
LQ Newbie
 
Registered: Dec 2004
Posts: 14

Original Poster
Rep: Reputation: 0
bm17 u r rite, that problem is complex but mine is not, it was the directory I placed it in...because now the file appears on the 'Command Prompt'

NEXT question is how do u run it ?? (which I'm trying as I speak or should I say 'as I write')
 
Old 12-22-2004, 11:58 AM   #11
bm17
Member
 
Registered: Sep 2004
Location: Santa Cruz, CA, USA
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
If you are just trying to experiment with the C language then you should create a DOS window/session (or command prompt, or whatever they call it these days) and type the name of the command (test). If you do not run it at the command prompt then you will not be able to see the output. I think that the cygwin compiler has an option to create a terminal window when you run the program, but I do not know how to invoke that option.
 
Old 12-22-2004, 12:08 PM   #12
killos
LQ Newbie
 
Registered: Dec 2004
Posts: 14

Original Poster
Rep: Reputation: 0
alright thanx I try that now....
 
Old 12-23-2004, 12:52 PM   #13
killos
LQ Newbie
 
Registered: Dec 2004
Posts: 14

Original Poster
Rep: Reputation: 0
Ok! - one more qiuck question, what is the symbol for 'infinite' in C Programming Language
 
Old 12-23-2004, 12:55 PM   #14
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
There's no such thing.
 
Old 12-23-2004, 01:12 PM   #15
bm17
Member
 
Registered: Sep 2004
Location: Santa Cruz, CA, USA
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
Quote:
Originally posted by itsme86
There's no such thing.
That is not entirely true. The floating point binary format allows for several special values, including infinity, negative infinity, and NaN (Not a Number, or "undefined"). They are obscure and only heavy-math guys use them. I know how to use these values with C++ but C is not so clear to me. My understanding is that you include math.h and use the macro INFINITY. You can do a google search for "C language float infinity" for more information.

Most people's first programs do not take numeric cardinality into consideration. Good show!

But I suspect I am missing something here. In what context do you need to use infinity? Are you talking about an infinite loop?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling narcussist Fedora 6 01-18-2006 12:50 PM
compiling z9_87 Linux - Software 4 12-23-2004 05:29 PM
Various Compiling Errors (GCC compiling Openal, GUIlib, xmms-wma) gregorya Linux - Software 2 08-27-2004 05:03 AM
Compiling in ACPI support on Compaq 2135CA (system crashes while compiling) Dag Linux - Laptop and Netbook 20 07-30-2004 07:56 PM
Kernel compiling and module compiling tarballed Linux - General 1 12-22-2002 05:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration