ClassCertificates #include stdlib.h not clearing warning


#1

I’ve included stdlib.h in the example code but am still getting the invalid implicit declaration warning on the first sleep(2) statement.

Here is my code:

[code]#include <stdio.h>
#include <stdlib.h>

void congratulateSudent(char *student, char *course, int numdays)
{
printf("%s has done as much %s programming as I could fit into %d days.\n", student, course, numdays);
}

int main (int argc, const char * argv[])
{

// insert code here...
printf("Hello, World!\n");

congratulateSudent("Mark", "Cocoa", 5);
sleep(2);
congratulateSudent("Bo", "Objective-C", 2);
sleep(2);
congratulateSudent("Eric", "Zen", 1);
sleep(2);
congratulateSudent("Jane", "C", 3);

return 0;

}[/code]

What am I missing?

Running Xcode 4.2.


#2

Hi Community this is my first post on this Forum

@ehamburg
Just read on like i do :wink:

Weiterlesen hilft wie bei mir :wink:

Best
modus25


#3

As declared later in the book, this is what usually happens, you should ignore the error.

Hamburg, die schönste Stadt der Welt <3


#4

If you look at the docs for the function, you can see that you should include unistd.h. I don’t know if the sleep function in earlier Xcode versions was declared in stdlib.h but in Xcode 4.2 you should use unistd.h to get rid of the warning.


#5

@rohdester - unistd.h got rid of the warning. Thanks.


#6

Also for 4.1 you need to include unistd.h, not sure about earlier versions, but probably not a lot of people will use older Xcode versions anyway.


#7

@rohdester – Thanks for the tip!


#8

I’m not sure if it’s a good idea, but changing the C Language Dialect (under Build All) to ANSI-C from GNU-99 clears the warning.


#9

I too was curious as to why I was receiving an Implicit Declaration.

As mentioned earlier by @rohdester The sleep function looks to be declared in unistd.h

http://www.gnu.org/software/libc/manual/html_node/Sleeping.html

Replacing #include <stdlib.h> with #include <unistd.h> resolved the issue.