W
W. Van Hooste
Hello,
I'm writing a program to display somme values as nice X graphics for a
special purpose. Under here is part of my main code and part of the
code to gather the sample data. the sample data can be gathered in
many ways (mostly API's) but i'm experimenting with a datafile right
now. The data file looks like this :
8<-----------
Unclassified 0
Class_3a 22
System 6
-
Unclassified 2
Class_3a 21
System 7
-
----------->8
In the module i open the file, read formated data, return it, and draw
in my main program. This works nice for the first set (3+1 lines), but
if i come back to the while loop in my main program and want to gather
the second set of data (startig with "Unclassified 2") my file pointer
(fpt) in module1 is lost, it is sometimes changed to another value or
changed to 0x0!
What am i missing here??
main program:
183 void timerCB(XtPointer client_data,XtIntervalId* id)
184 {
185 MyData data;
186 int sampledata[MAX_CLASSES];
187 int class, count;
188
189 data = (MyData) client_data;
190 /* printf("Timer CB\n"); */
191 printf("------\n");
192
193 count=GetSampleCount();
194 class=count;
195 while (--class>=0) {
196 sampledata[class]=GetSampleData(class);
197 printf("%d \n",sampledata[class]); /* debug */
198 };
199 AddSample(data, count, sampledata);
200
201 /* PrintSampleStruct(data); */
202
203 XClearArea(XtDisplay(data->drawa),XtWindow(data->drawa),1,1,data->width,data->height,TRUE);
204 XtAppAddTimeOut(data->app_context,REFRESH,timerCB,data);
205 }
module1:
32 int
33 GetSampleData(int sample)
34 {
35 FILE *fpt;
36 char str[80];
37 int sval;
38
39 /*
40 * return (int)(random()%20);
41 */
42
43 if (filestat == 0) {
44 fpt = fopen("wlmdata.out", "r");
45 filestat = 1;
46 };
47
48
49 if (fscanf(fpt, "%s %u", str, &sval) != -1) {
50 if (str[0] != '-') {
51 printf("%s = %u \n", str, sval); /* debug */
52 return (int) (sval);
53 };
54 return (int) (0);
55 } else {
56 fclose(fpt);
57 };
58
59 }
Thx,
W. Van Hooste.
I'm writing a program to display somme values as nice X graphics for a
special purpose. Under here is part of my main code and part of the
code to gather the sample data. the sample data can be gathered in
many ways (mostly API's) but i'm experimenting with a datafile right
now. The data file looks like this :
8<-----------
Unclassified 0
Class_3a 22
System 6
-
Unclassified 2
Class_3a 21
System 7
-
----------->8
In the module i open the file, read formated data, return it, and draw
in my main program. This works nice for the first set (3+1 lines), but
if i come back to the while loop in my main program and want to gather
the second set of data (startig with "Unclassified 2") my file pointer
(fpt) in module1 is lost, it is sometimes changed to another value or
changed to 0x0!
What am i missing here??
main program:
183 void timerCB(XtPointer client_data,XtIntervalId* id)
184 {
185 MyData data;
186 int sampledata[MAX_CLASSES];
187 int class, count;
188
189 data = (MyData) client_data;
190 /* printf("Timer CB\n"); */
191 printf("------\n");
192
193 count=GetSampleCount();
194 class=count;
195 while (--class>=0) {
196 sampledata[class]=GetSampleData(class);
197 printf("%d \n",sampledata[class]); /* debug */
198 };
199 AddSample(data, count, sampledata);
200
201 /* PrintSampleStruct(data); */
202
203 XClearArea(XtDisplay(data->drawa),XtWindow(data->drawa),1,1,data->width,data->height,TRUE);
204 XtAppAddTimeOut(data->app_context,REFRESH,timerCB,data);
205 }
module1:
32 int
33 GetSampleData(int sample)
34 {
35 FILE *fpt;
36 char str[80];
37 int sval;
38
39 /*
40 * return (int)(random()%20);
41 */
42
43 if (filestat == 0) {
44 fpt = fopen("wlmdata.out", "r");
45 filestat = 1;
46 };
47
48
49 if (fscanf(fpt, "%s %u", str, &sval) != -1) {
50 if (str[0] != '-') {
51 printf("%s = %u \n", str, sval); /* debug */
52 return (int) (sval);
53 };
54 return (int) (0);
55 } else {
56 fclose(fpt);
57 };
58
59 }
Thx,
W. Van Hooste.