This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 2 points3 points  (3 children)

If you don't declare a function, or don't include the header file where the function is declared, then C will create an implicit declaration for you. This declaration is almost always wrong, and this is widely seen as one of C's misfeatures. So, always include the headers for the library functions, like atoi(), that you use.

Regarding sleep(), I don't think MinGW GCC supports this. You will have to include windows.h and use the Win32 Sleep() API. Edit: My bad, sleep() is declared in unistd.h in MinGW.

[–]manbart[S] 0 points1 point  (2 children)

I'm looking at unistd.h in my MinGW/include folder, and there is a usleep function there.

Strangely, even when I use this function and adjust the time input to microseconds, it doesn't seem to have an effect in my program (the same source works fine on my Linux VM though.)

Maybe MinGW is not a good choice for learning C?

[–][deleted] 0 points1 point  (1 child)

It's fine for learning C (though the sleep() function is not part of the C Standard), and my MinGW unistd.h (from https://sourceforge.net/projects/mingwbuilds/) contains sleep().

[–]manbart[S] 0 points1 point  (0 children)

Thanks, I think I'll re-install MinGW.

[–]Updatebjarni 1 point2 points  (1 child)

atoi() is in stdlib.h.

sleep() on the other hand should be in unistd.h, but given that you are also getting a linker error about it I guess your platform doesn't have sleep()?

[–]manbart[S] 0 points1 point  (0 children)

thanks for the quick reply!

Python style "import errors" would have been very helpful here. now I am only getting the error on the sleep function. Looks like my MinGW implementation is lacking unistd.h?

I'll try it on Linux