Get filename from input

I want to input a filename from input, then open a file with that name. If doesn't exist, create one.
I tried this but wouldn't work. Any idea?
1
2
3
4
5
6
  char filename[10];
  scanf("%s", filename);
  FILE *clientfile;
  FILE *serverfile;
  clientfile = fopen("client/"filename, "r");
  serverfile = fopen("server/"filename, "a+");

The name doesn't exactly have 10 characters. But I don't how many char will it be. Let's assume it is less than or equal to 10.
Huh, so do you want a get a file and append to that file, after doing some calculate with the values in the file or do you want to create a brand new file with a similar name?

I just can't tell what you meant by,
tomtran3110 wrote:
I want to input a filename from input, then open a file with that name.


I keep thinking that you want to just append to that file bcs if you have a file as input that's user defined then you will never not have a file... Is that what you want?

Hope this helps,

~ Hirokachi

Edit: maybe you want a user to define a filename and create a file with that filename...
If so then maybe you want to reread the tutorial on files on this site.
URL: http://www.cplusplus.com/doc/tutorial/files/
Last edited on
Does it have to be coded in C?

If not, then http://www.cplusplus.com/doc/tutorial/files/
Silly me, simply strcat() had solved my problem. Thanks anyway!
Topic archived. No new replies allowed.