File names

This is a discussion on File names within the C Programming forums, part of the General Programming Boards category; Hi ! I am writting a C program on unix platform. I need create many files with the same first ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    1

    File names

    Hi !

    I am writting a C program on unix platform.
    I need create many files with the same first part of the name but ending with increasing numbers like (file01, file02, file03...). Does someone know how to do that automatically ?
    Thanks for the help.

    Nzanya

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Use sprintf.
    Code:
    for (i = 0;i < 100;i++)
    {
        char file_name[PATH_MAX];
    
        sprintf(file_name, "file%02d", i);
    
        printf("File name is %s.\n", file_name);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File being filled with NULLs
    By Tigers! in forum Windows Programming
    Replies: 2
    Last Post: 06-30-2009, 06:28 PM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 08:01 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21