-
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
-
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.
-
Basically, you just have to convert your int to a string.
I suggest you look into the function in stdio called
sprintf
-
I believe MSVC++ 6 allows itoa() unlike UNIX to convert your int to a string. Confused, what platform are you working on ?
-
Just use sprintf, like already suggested:
Code:
while( !done )
{
sprinf( buf, "%d.dat", number );
fp = fopen( buf, "wb" );
...do stuff...
fclosef( fp );
}
Quzah.
-
variable types
Quote:
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