Thread: converting a program from unix to windows

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    18

    converting a program from unix to windows

    hello,

    i'm wondering if anybody out there could point me to a tutorial or FAQ on porting a unix C program to windows?

    specifically, i'm getting an error when i compile with the following functions defined:

    Code:
    srand( (unsigned)time( (time_t *) 0 ));
    to seed srand. the error is:

    'time': identifier not found, even with argument-dependent lookup

    also,

    Code:
    mkdir(theFolder, 00777);
    with the same error code. it may be my headers are incorrect, so i'll list them too:

    #include <iostream>
    #include <tchar.h>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <sys/types.h>
    #include <sys/stat.h>

    any help or advice would be appreciated. i'm using visual studio to compile.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    time() is in <time.h>. mkdir() is often in <unistd.h>.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    here you go:
    Code:
    <stdlib.h>
    <time.h>
    
    srand( (unsigned)time( (time_t *) 0 ));
    As for mkdir, since dos died, I'm not too sure, sorry...
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    As for mkdir, since dos died, I'm not too sure, sorry...
    mkdir() is a POSIX function.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Why are you including iostream? That's for C++.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    mkdir() is one of the few POSIX standard functions that most Windows compiler also support.

    Waltr: there are many *nix functions that have no MS-Windows equivalents, and others have different function names with similar functionality. For example, *nix opendir() and readir(), MS-Windows equivalents are ReadFirstFile() and ReadNextFile().

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    18
    hi all,

    thanks for the replies. <itsme> i'm not sure why i had <iostream> in there. it's not necessary so i've removed it.

    <time.h> has solved my
    Code:
    srand( (unsigned)time( (time_t *) 0 ));
    problem, but i still can't seem to get the mkdir() function to work.

    any other suggestions are welcome, if i solve it myself i'll post the answer. thanks again!

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    It looks like you should be able to use mkdir() if you #include <direct.h>
    If you understand what you're doing, you're not learning anything.

  9. #9
    Registered User
    Join Date
    Sep 2004
    Posts
    197
    Quote Originally Posted by dwks
    mkdir() is a POSIX function.
    And he is porting the program to Windows...
    If any part of my post is incorrect, please correct me.

    This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted.

  10. #10
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    mkdir() is a POSIX function.
    And he is porting the program to Windows...
    :
    mkdir() is one of the few POSIX standard functions that most Windows compiler also support.
    Besides, that wasn't my point. My point was that is isn't a DOS function:
    As for mkdir, since dos died, I'm not too sure, sorry...
    Which is also your point.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #11
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    "DOS is not dead, it just smells funny"
    -- me and Frank Z...
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  12. #12
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Quote Originally Posted by itsme86
    It looks like you should be able to use mkdir() if you #include <direct.h>
    The Visual Studio compilers have a _mkdir function in that header... perhaps that can be used.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    *frowns*
    A 2-Month bump
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. Running program in unix
    By Cpro in forum Linux Programming
    Replies: 2
    Last Post: 02-10-2008, 09:28 PM
  3. memory leak checker program? for windows
    By rahulsk1947 in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 07:20 AM
  4. Program works on Windows XP and 2000, not on 98 or ME
    By MidnightlyCoder in forum C++ Programming
    Replies: 7
    Last Post: 03-10-2006, 03:36 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM