I'm using the following piece of code (received some time ago from Ian) to call
from file txt frequency values which my audio sinth reads and therefore with
them produces sounds.
At the moment I'm able to go to next line and so on up to EOF and then read the
file from the beggining. I'm not able to return to a previous line from a next
line. I'm trying to implement some method to do it.
I appreciate your suggestions to solve the problem
thank you in advance
Ivano
FILE *fp_123 = NULL;
// Hack file parser - you really want to do somethng better!
void next_entry_123(void)
{
//FILE *fp_123 = NULL;
char values[1024];
int n1_123, n2_123, n3_123, n4_123;//float original
// is our file open?
if(!fp_123)
{
puts("fopen");fflush(stdout);
char name[1024];
strncpy(name, fname_123->value(), 1024);
if(strlen(name) < 2) return;
// needs more robust checking!
fp_123 = fopen(name, "r"); // open file read only
if (!fp_123)
{
puts("file open failed!");
puts(name); fflush(stdout);
return;
}
}
next_line:
// get the next line from the file
char *pc = fgets(values, 1024, fp_123);
if(pc == NULL)
{
// are we at EOF?
if(feof(fp_123))
{
// rewind the file
fseek(fp_123, 0, SEEK_SET);// rewind too
goto next_line;
}
else return; // we are broken in some way
}
// is it a comment?
if(values[0] == '#') goto next_line;
// is it a blank line
if(strlen(values) < 4) goto next_line;
// parse the line
int res = sscanf(values, "%d %d %d %d",
&n1_123, &n2_123, &n3_123, &n4_123);
if (res != 4)
{
puts("Bad Values line read");
}
else
{
etc. etc.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk