#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    C - Language User input to create text file


    Hi

    (I have Windows 7 and am using Visual studio Professional 2012)

    I am a new C language student and am trying to write a program.

    In the start of the program, I want the user input, his name, to be created as a txt file, with his name as the file name.( I will then save data there)

    Is it possible to use the user input to create a file name?

    I have looked at scanf, gets, fgets - but none seem to have this facility.

    I have also googled this and cannot find any sort of answer.

    Could anyone provide some advice as to where I should start looking.

    Thanking you in anticipation.

    Regards

    Michael S

    PS I am not looking for code, just a pointer in the right direction if possible.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,223
    Rep Power
    2222
    Is it possible to use the user input to create a file name?
    Yes. strcpy, strcat, sprintf. Take your pick or mix and match.
  4. #3
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4247
    Look into fopen() and note the first parameter is the name of the file.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,223
    Rep Power
    2222
    And realize that when you create the file, it will be in the program's current directory, which should probably be where the .EXE file is stored (I haven't played with file operations in recent versions of Visual Studio).

    Oh, and if your course requires you to learn C99, then be advised that Visual Studio does not support it.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0
    Thank you one and all.

    This gives me a starting point.

IMN logo majestic logo threadwatch logo seochat tools logo