[noob] sysfile_write() empty file

Jun 20, 2013 at 3:52pm

[noob] sysfile_write() empty file

I am trying to understand the reading and writing portions of the SDK and am having trouble with the sysfile_write(). I got sysfile_writetextfile() to work but am stuck with this.

I followed the documentation but the resulting textfile, while 100 bytes large, is empty. Here is the code:

void buffTest_writefile(t_buffTest *x, char *filename, short path)
{
char *buf[100];
t_fourcc filetype = 'TEXT';
t_ptr_size count;
long err;
t_filehandle fh;
for (int i = 0; i < 100; i++) {
buf[i] = i + 1;
}
count = 100;
err = path_createsysfile(filename, path, filetype, &fh);
if (err)
return;
err = sysfile_write(fh, &count, buf);
sysfile_close(fh);
}

Any pointers would be appreciated ;)

Max 6.1.3
SDK. 6.1.1
OSX 10.8.4

#253486
Jun 20, 2013 at 3:56pm

… and while I am here. Why is there a short numtype = 1; in the example? It is never used as far as I can tell…

#253487
Jun 20, 2013 at 4:17pm

the code is questionable. I am unsure what you are trying to do, but I see several concerns.

char *buf[100]
that creates an array of 100 slots where each slot is a pointer to a char
I suspect, you intend to declare it instead to be:
char buf[100];

later in the code, you pass buf to sysfile_write. buf means the pointer to the first element of buf. So its a pointer to a pointer. And that’s weird. Not what you probably want to give to sysfile_write.

Also, the 2nd param to sysfile_write should be a pointer to a long. Therefore, I would declare it to be:
long count;
and then call it like this:
err = sysfile_write(fh, &count, buf);

#253489
Jun 20, 2013 at 4:24pm

Ah, I could be wrong. The SDK doc is wrong on this topic area so you might have to experiment.
Also read this post http://cycling74.com/forums/topic/problem-with-sysfile_writetextfile/

#253492
Jun 20, 2013 at 4:24pm

according to the .h file it’s not a long but like this t_max_err sysfile_write(t_filehandle f, t_ptr_size *count, const void *bufptr);

not sure about the buf thing… it’s straight out of the SDK help… not sure what to do about that.

#253493
Jun 20, 2013 at 4:25pm

already tried that, thanks.

#253494
Jun 20, 2013 at 4:32pm

not sure this will help, but here is the resulting .txt file.

Attachments:
  1. count100.txt
#253495

You must be logged in to reply to this topic.