Thread: Header file location confusion

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    2

    Header file location confusion

    I'm learning C programming and I don't have a background in programming. I want to control the timing of commands for a simple console program and looked up online the sleep() function. However, it requires the <unistd.h> header file. I'm using Visual Studio .Net on my work computer (because my lab has that on all computers.) However, when I put:

    #include <unistd.h>

    or

    "#include "unistd.h" at the beginning of the program, I get the error:

    fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory

    So I looked up online that the unistd.h header file is part of the POSIX library as opposed to the ANSI library. Perhaps that is meaningless, I don't know.

    Question 1: How do I know what header files I have access to with the Visual Studio .net software?

    Question 2: Can I download unistd.h from somewhere on the web and put it somewhere so that my program will know where to access it?

    thanks in advance.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    I can't answer either of your two questions, but if you want to do a sleep under windows, you can use Sleep (note the S is capital).
    Code:
    #include <windows.h>
    .
    .
       /* Sleep for 1000 milliseconds */
       Sleep(1000);
    Note this solution is obviously nonportable. I believe most linux flavors would have sleep and probably usleep, because as you said, these are POSIX.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    2
    Swoopy,

    Thanks! That worked perfectly and solved my problem. I didn't occur to me (being a newbie) that sleep() could be in multiple header files.

    If anyone can answer my previous questions about header file locations, that would be great. I would still like to better understand header files and libraries.

    thanks!

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    You could always compile under Cygwin to access POSIX functions.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    If anyone can answer my previous questions about header file locations, that would be great. I would still like to better understand header files and libraries.
    (1) I don't use Visual Studio .net, but it will certainly have all the C standard library functions. Here's a reference: http://www.cppreference.com. It will also have the Win32 API functions found in <windows.h>. There should be some documentation which accompanied it.

    (2) unistd.h is typically available on linux/unix systems. There's also a FAQ entry for this question: FAQ > How do I... (Level 1) > Where can I download a missing header file?

  6. #6
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    So it seems the short answer is that the OP found an example from a UNIX system and that he is using Windows. I would guess that unistd.h is short for Unix Standard Header file and Windows.h is short for Windows (Standard) Header file. Makes sense to me amyway!!

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >So it seems the short answer is that the OP found an example from a UNIX system and that he is using Windows.
    That would be my guess. Stuff like sleep is platform specific. I'm using Dev-C++ right now, which has <unistd.h>, but it's missing a lot of the unix/linux functionality.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. location of header file definitions
    By NuNn in forum C Programming
    Replies: 4
    Last Post: 03-25-2009, 09:26 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM