Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

C Programming - Compile (CTRT+F9) problems


  • Please log in to reply

#1
blrjohn07

blrjohn07

    Member

  • Member
  • PipPip
  • 55 posts
Guys...

I dont' know how to start. I am very new user about C. I need all of your help. I am getting some problem when i want to compile my program...see below short program

#include
<stdio.h>

int main()
{
printf( "I am alive! Beware.\n" );
getchar();
return 0;
}


when i m pressing CRTL+F9 ..its not showing me the output. one dos screen is just blinking on dat time....Please help..


Even I will b glad if u guys help me about starting C. I wanna learn any how. How to start ..from where to start ...no idea about dis. waiting for prompt reply

Edited by blrjohn07, 17 December 2007 - 01:58 PM.

  • 0

Advertisements


#2
Swandog46

Swandog46

    Malware Expert

  • Member
  • PipPipPipPip
  • 1,026 posts
  • MVP
I guess you're using Dev-C++? (since Ctrl-F9 is 'compile' for me, using Dev-C++.)

In any event, this program won't compile for a whole lot of reasons. But before I get to that, when you push Ctrl-F9 and compilation fails, check the bottom of the Dev-C++ screen, the "Compiler" tab should list all the errors that caused it to fail.

Here are the errors you get and explanations of why you get them.

Line 1: #include expects "FILENAME" or <FILENAME>

Your #include <stdio.h> should all be on one line.

Line 2: Syntax error

Related to above, since <stdio.h> is bad syntax on its own.

Now, if I fix this and put
#include <stdio.h>
on a single line, the program compiles and does what you expect it to do. But even so there are still a few other problems with it! It is not good ANSI-compliant C code to declare 'main' as taking no arguments. The prototype for 'main' should be

int main(int argc, char **argv)

where the argument 'argc' is the "Argument Count", the number of command-line arguments passed to your program, and 'argv' is the "Argument Vector", the array of the command-line arguments.

It is also bad form to use getchar() as a 'pause' function -- I assume that is why you put it in? Since you don't do anything with the character you get, you just throw it away. If you want to write in a pause function, (although this is Windows-dependent, not ANSI), it is better style to do:

system("pause");

This will execute a system call as if you were directly typing on the command line, and the "pause" command is the DOS command that returns the "Press any key to continue..." prompt.

I believe you have to #include <stdlib.h> in order to get the system() function.

So this is how the program should read:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
printf( "I am alive! Beware.\n" );
system( "pause" );
return 0;
}

  • 0

#3
blrjohn07

blrjohn07

    Member

  • Topic Starter
  • Member
  • PipPip
  • 55 posts
dude..many thanks for your nice help....

actualy i m not using dev c++...i m using turbo c++ version 3.0

now i got the solution buddy...

Please suggest me how shoud i start learning C ????
  • 0

#4
Swandog46

Swandog46

    Malware Expert

  • Member
  • PipPipPipPip
  • 1,026 posts
  • MVP
Turbo-C++ 3.0 came out in 1991. You might consider using a more up-to-date development environment. :)
Dev-C++ is free, based on mature GNU/GCC compilers, and easy to use.

I Googled "C Programming" or "C Programming Tutorial" and got lots and lots of decent-looking hits.

I liked this tutorial especially when I was first learning:
http://www.eskimo.co...ass/cclass.html

C is not an easy language if it is your first language, but it is the basis of most common modern languages, and if you become comfortable with it you can teach yourself most anything else.
  • 0

#5
blrjohn07

blrjohn07

    Member

  • Topic Starter
  • Member
  • PipPip
  • 55 posts
Many thanks...even from yesterday I started using dev c++. I wrote a small program and it worked. I will b keep on asking my problems if u allow me...
  • 0

#6
Swandog46

Swandog46

    Malware Expert

  • Member
  • PipPipPipPip
  • 1,026 posts
  • MVP
Sure. :)
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP