Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does fopen fail the first time, but work the second time?

I am using Matlab to create a new file by calling

fid = fopen(filename,'w')

since filename doesn't exist, it should create a new file and give me a valid file descriptor. Instead it returns -1. If I run the code again however, I get fid = 3.

This is being run on ubuntu but it apparently works fine on windows and I can't figure out why.

-Mike

like image 852
msandbot Avatar asked Jan 20 '26 08:01

msandbot


1 Answers

not sure if this helps, but note that if the folder doesn't exist, fopen with 'w' can't create the file and so returns -1.

like image 85
second Avatar answered Jan 21 '26 22:01

second