Search code examples
cfileabsolute-path

Get path from input to read a file


I would like to get a name of file from input and then read it. (Suppose that the file is in the directory of program.) To do that I need an absolute path. Please let me know how to achieve this goal using C. This a part of my code:

scanf("%s",&filepath1);
FILE * fdw = fopen(filepath1, "a");

Solution

  • delete the '&' symbol.

    char filepath1[SIZE] = {0};
    
    scanf("%s", filepath1);
    
    FILE * fdw = fopen(filepath1, "a");