fopen woes

Hi,
Newbie question/problem. I have a list of files which are being opened by fopen and the data within given to variables. This currently works fine but i have to manually edit the code to change the file i wish to read, currently in the form barXsideY.txt where X is a number and Y is a letter.

How would it be possible to use allow the user to choose bar number, X, and bar side, Y, and feed with user altered file name into fopen(filename,mode)?

Any more details easily forthcoming if needed.
you can use sprintf function for it
As an example.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int x;
char y ;
char fileName[ 200 ] ;
FILE *fileT ;
printf( "Enter bar number : " );
scanf( "%d",&x );
printf( "\nEnter letter : " );
scanf( "%c",&y );

sprintf( fileName ,"bar%dside%c.txt",x,y);

fileT = fopen( fileName , "r" );  
...
...
fclose( fileT );

I didn't test the code .But i guess
 
sprintf( fileName ,"bar%dside%c.txt",x,y);

this line is what you want.
Thanks, seems to be good.
Topic archived. No new replies allowed.