Enter custom file name to be read ?

Posted by ZaZu on Stack Overflow See other posts from Stack Overflow or by ZaZu
Published on 2010-05-08T19:45:40Z Indexed on 2010/05/08 19:48 UTC
Read the original article Hit count: 132

Filed under:
|
|

Hello,

I want to allow users to type the name of any .txt file to be read/written.

This is my code :

  printf("Enter .txt file name\n");
  scanf("%s",&fname);
  FILE *inputf;
  inputf=fopen(&fname,"w");

Problem is this method does not work (having &fname) as a parameter.

I can imagine its because C needs "filename.txt" for it work ... even if I enter for example : "custom.txt", the program returns an error of "Storage block not big enough for this operation"

What is the correct method to accomplish this ?

Im using C and im pretty much using basic commands .. (not too advanced)

Thanks alot !!!

© Stack Overflow or respective owner

Related posts about file-io

Related posts about files