0

Trying to open file in a relative path, Path is different everytime, I want to use a char as path

Currently I have:

char path[128];
strcat(path, "/home/pi/Analyses/");
strcat(path, lstAnalyse);
strcat(path, "/data.txt");
fopen(path, "a");

What is the right way to use a char as path with fopen ?

SimonCo
  • 11
  • 3
  • 2
    First `strcat` is UB as `path` is uninitialized. Replace it with `strcpy`. Or simply initialize `path` with the first string... – Eugene Sh. Jun 15 '18 at 14:32
  • Either change `strcat(path, "/home/pi/Analyses/");` to `strcpy(path, "/home/pi/Analyses/");`, or change `char path[128];` to `char path[128] = "";`. – Steve Summit Jun 15 '18 at 15:16

0 Answers0