2

I have just started to learn C language and I'm just trying to write Hello World to get started but I get this error message. I'm sure the answer is obvious but can someone please tell me what I need to do? This is my code:

#include <stdio.h>

int main()
{
printf("Hello World ");
system("Pause");
    return 0;
} 
inf3rno
  • 24,976
  • 11
  • 115
  • 197
user1984103
  • 57
  • 1
  • 3
  • 6
  • 5
    `system("pause");` makes me cry. http://stackoverflow.com/questions/1107705/systempause-why-is-it-wrong – Fred Larson Jan 16 '13 at 15:14
  • @FredLarson: FYI [Markdown Link](http://daringfireball.net/projects/markdown/syntax#link) syntax is supported in comments, useful to avoid long URLs. –  Jan 16 '13 at 15:24

6 Answers6

3
#include<stdlib.h>

Include this header file..

Raghu Srikanth Reddy
  • 2,703
  • 33
  • 29
  • 42
2

You need to add another header file:

#include <stdlib.h>

When you have an undefined call like this you can always throw "man 3 system" and you'll get something like this so you can see if you're missing a header file.

FYI, for your specific program, you may want to consider no using system("Pause") since it's system dependent. It would be better to pause with a break point (if you're using an IDE) or something more C standard like getchar()

Mike
  • 47,263
  • 29
  • 113
  • 177
1

You need to #include <stdlib.h>

If you aren't sure which header a standard function is defined in, its man page will tell you.

simonc
  • 41,632
  • 12
  • 85
  • 103
  • 1
    A better reference is the C standard, www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf. Search for "the nn function" where nn is the name of the function you are looking for. "man" contains various Linux-related goo that is not necessarily standard compliant. – Lundin Jan 16 '13 at 15:42
1

Insert

#include <stdlib.h> //in C

or

#include <cstdlib> //in C++

before your main() function.

Note that your IDE should refrain from closing your program. If it doesn't, change IDE.

milleniumbug
  • 15,379
  • 3
  • 47
  • 71
1

You should include the following library.

 #include <stdlib.h>

It's simple as that. I hope you find this useful.

miksiii
  • 2,426
  • 26
  • 22
0

As the others said, you need to include an header; if you're running on Linux, you may install "manpages-dev" package, and then tape "man system" which will tell you what are the headers you need to use.

bagage
  • 1,094
  • 1
  • 21
  • 44