Thread: Sequential Filenames?

  1. #1
    Confused
    Guest

    Unhappy Sequential Filenames?

    Hi all,

    i am in desperate need of help... i've got a simple maths problem that requires performing a series of calculations on a series of single integers...

    i have the program to do the calulations, but i want to fully automate it, and would like to output the results to a file, whos name is the same as the number which the operation is carried out on... EG. if i was doing the calculation on the number 335 i would like the file to be called 335
    fopen will only allow 'const char' to be used an an input? how do use variable filenames???

    please please help
    thanks in advance

    Si-man

  2. #2
    Sayeh
    Guest
    Have you considered writing a little function that converts your integer into a string?

    'const char' is a string. the file io routines wants a string passed to it.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Basically, you just have to convert your int to a string.

    I suggest you look into the function in stdio called
    sprintf
    Callou collei we'll code the way
    Of prime numbers and pings!

  4. #4
    Registered User goran's Avatar
    Join Date
    Sep 2001
    Posts
    68
    I believe MSVC++ 6 allows itoa() unlike UNIX to convert your int to a string. Confused, what platform are you working on ?
    I don't wait for the future; it comes soon enough.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Just use sprintf, like already suggested:
    Code:
    while( !done ) 
    {
        sprinf( buf, "%d.dat", number );
        fp = fopen( buf, "wb" );
        ...do stuff...
        fclosef( fp );
    }
    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    confused???
    Guest

    variable types

    Originally posted by quzah
    Just use sprintf, like already suggested:
    Code:
    while( !done ) 
    {
        sprinf( buf, "%d.dat", number );
        fp = fopen( buf, "wb" );
        ...do stuff...
        fclosef( fp );
    }
    Quzah.
    Argghhhhaaaa

    C hates me

    i havn't got the first clue how to define the variables for this routine... and i keep getting errors about how i cannot use one type of variable in the fopen statement.. but when i change the variable types one of the other statements doesnt work..

    can you tell me what each of the variables in the above statement should be ????

    thanks

    si

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. sequential file help plz
    By dutrachr in forum C Programming
    Replies: 4
    Last Post: 04-18-2006, 11:41 AM
  3. Getting filenames from a file
    By vinsta18 in forum C++ Programming
    Replies: 1
    Last Post: 01-12-2005, 11:52 AM
  4. reading filenames
    By Paul in forum C++ Programming
    Replies: 1
    Last Post: 07-01-2003, 10:02 AM