I'm connecting a BeagleBoneBlack with a IMU using I2C protocol. I already read data in console great but when im trying to store data in a .txt file, it return me error: Segmentation fault.
int I2C_open()
{
int file;
char *dev = "/dev/i2c-1";
if ((file=open(dev,O_RDWR))<0);
{
perror("Abrir el canal");
}
return file;
}
int main()
{
archivo=I2C_open();
f=fopen("./home/debian/Desktop/Comunicacion/Prueba.txt","W");
fprintf(f,"Datos leidos del sensor");
}
This is just part of the code because it's large. The problem is presented when i use the fprintf, when i commented that line the code run well. Im not sure if is because im using fopen while "/dev/i2c-1" is running. Please help
gccsay when-Wallis passed to it? Where does the error occur when you runstraceagainst it? - alvitsfopen()is relative path. Does the path exist? Did you check iffopen()returns non-NULL file desc? - alvitsfopen()returnNULLbecause it can't create file in inexistent directory. Use full path instead of relative path in specifying file. Or don't specify a path and file will be created in current working directory. - alvits