i know how to use fopen to read a file, but i have a changing file name like this "p%dt%03d.state" where the variables are changing inside a loop. eg : p1t001.stae, p1t002.state ... etc

how will i be able to do that?

thanks!!

use sprintf() to format the file name

char filename[255];
int i;
for(i = 1; i< 10; i++)
{
   sprintf(filename,"p1%03d".state",i);
   printf("filename = %s\n", filename);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.