What's New!

Chat with
Hackers

How to Defend
Your Computer 

The Guides
to (mostly) 
Harmless Hacking

Happy Hacker 
Digests (old stuff) 

Hacker Links 

Hacker
Wargames 

Meet the 
Happy Hacksters 

Help for 
Beginners 

Hacker 
Bookstore 

Humor 

It Sucks 
to Be Me!

How to Commit
Computer Crime (not)! 

What Is a 
Hacker, Anyhow? 

Have a 
Great Life! 

News from the 
Hacker War Front

How to Program in C,continued...

Troubleshooting

Did your program not run? Let's do some trouble shooting. First, say over and over again, "I love Unix. I swear I do! Honest! I love C, too!" Now try to compile and run this program another way. You start with the same code as before, which is saved in the file "hello.c". However, this time, give the command:

cc -o hello hello.c

What this does is:
1) start your C compiler running with the "cc" command using the -o switch. A quick use of the command "man cc" tells us that the switch "-o" after the "cc" tells your compiler to output the compiled version as a file with the name of your choice.
2) the "hello" part of the command tells the compiler that this is what you want to name your compiled program
3) with the 'hello.c" part of the command you tell the compiler where to find the source code you just wrote which you input into the compiler.

Now -- simply give the command "hello". Your computer should say back to you, "Hello, hackers!" Congratulations! You are now a C programmer.

Still doesn't work? Try giving the command "chmod 700 hello". STILL doesn't work? This is a long shot, but maybe it will solve your problem. If your shell account is set up like mine, no program can execute from the home directory. It's a precaution I take against Trojans. (Imagine this, sometimes meanies put surprises in my account.) However, I have a directory named "bin" in my account. Normally on Unix systems we name directories that hold programs "bin". On my account, that's where I put the programs I write. So look for a directory "bin" under the home directory in your shell account. If it doesn't exist, create it with the command "mkdir bin". Don't forget to give the command "chmod 700 ~/bin" afterwards! Move "hello" into it with the command "mv hello bin/hello".

STILL DOESN'T WORK??? Here's the bad news. There are so many kinds of Unix, and so many shells to interpret your commands, and so many ways to configure Unixes -- I may not be able to solve your problem. As the C bible that we like to call simply "K&R" (The C Programming Language by Kernighan and Ritchie) warns, "Just how to run this program depends on the system you are using."

So don't phone or email me for help. Call tech support at your ISP! That's what you are paying them for, right? They WILL get your C program working -- if they allow users to compile C programs. You may even make friends with the tech support guy you call, as it is really rare and usually makes tech support guys happy when a customer asks a programming question instead of the usual lame stuff.

However, before calling tech support, maybe you had better rewrite your program first to say "Hello, world" instead of "Hello, hackers!" just in case the tech guy you talk to is paranoid enough to kick you off for trying to be a hacker.

More on C --->>


Carolyn's most
popular book,
in 4th edition now!
For advanced
hacker studies,
read Carolyn's
Google Groups
Subscribe to Happy Hacker
Email:
Visit this group

 

Return to the index of Guides to (mostly) Harmless Hacking!

 © 2013 Happy Hacker All rights reserved.