Problem with fopen filepath nesting

Hello Forum Members,
I’m having trouble opening a csv file using ‘fopen’. When the file path reads as below, there are no problems opening the file “sample.csv”:

FILE *fp;
char *fname = "/home/dakar/topas/ mean/cav4MV_Varian_PMMA16Mp_air_X8cm_2/sample.csv";
fp = fopen( fname, "r" );

However, I get an error message and am unable to open the file if I increase the file nesting by one folder as below:

FILE *fp;
char *fname = "/home/dakar/topas/ mean/cav4MV_Varian_PMMA16Mp_air_X8cm_2/4MV_0_2T_1D/ sample.csv";
fp = fopen( fname, "r" );

Does anyone know how to solve this problem.

Regards,
RL


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Do you really have a space character inside “4MV_0_2T_1D/ sample.csv”?

You are right that the space character should not be there i.e. the file path should read:

"/home/dakar/topas/ mean/cav4MV_Varian_PMMA16Mp_air_X8cm_2/4MV_0_2T_1D/sample.csv"

But after correcting it by removing the space character, it still doesn’t work.

That character space is supposed to be there. The original version of the file path i.e.

"/home/dakar/topas/ mean/cav4MV_Varian_PMMA16Mp_air_X8cm_2/sample.csv"

works just fine. It is the addition of an additional folder that causes it to stop working.

I think the problem is something trivial. that the folder 4MV_0_2T_1D starts with a number. If the folder name consists of a string, then there appears to be no problem.

ls -al "/home/dakar/topas/ mean/cav4MV_Varian_PMMA16Mp_air_X8cm_2/4MV_0_2T_1D/sample.csv"

-rw-rw-r-- 1 dakar dakar 146 3月  13 16:23 /home/dakar/topas/ mean/cav4MV_Varian_PMMA16Mp_air_X8cm_2/4MV_0_2T_1D/sample.csv

It works now. All I did was copy the folder containing “sample.csv” and delete the original. For whatever reason it was unable to find the file path.