Author | Message | Time |
---|---|---|
dRAgoN | [code] BOOL __stdcall GetDxData(LPSTR data){ FILE *stream = fopen("Dx.cfg", "r"); char buf[2048] = ""; if(stream){ while(fgets(buf, sizeof(buf), stream)){ strtok(buf, "\r\n"); if(!strnicmp(buf, "Dx9Data1=", 9)) sprintf(data, "%s", buf + 9); } } fclose(stream); return TRUE; } [/code] Yes i got motivated enough to finish this myself go nuts works fine <<-- Edit | June 15, 2003, 9:11 PM |
Eibro | char * strtok ( const char * string, const char * delimiters ); strtok returns a pointer the first occourance of any characters included in delimiters, you're completly discarding the return value of it. Also, if buf contains more than one newline, that call will only return the first occourance. You need to call strtok multiple times to find multiple newlines in buf. Look here: http://www.cplusplus.com/ref/cstring/strtok.html for an example of using strtok. It seems to me you should be using something like fgetln instead. But then again, I usually use C++ stream objects for working with files. Also, I'd advise against using the name of a C++ class as a variable name, (fstream) simply including fstream will give you errors. | June 15, 2003, 9:33 PM |
dRAgoN | strtok wasent the problem, It was just the way i was going about doing the function anyway that Edit is the way i ment for it to work. | July 25, 2003, 6:27 PM |
Eibro | That call to strtok isn't doing anything. You're simply reading in 2048 characters and checking the first 9 chararacters against "Dx9Data1=". So if "Dx9Data1=" doesn't reside at the head of the chunk, you won't find it. | July 25, 2003, 6:58 PM |
Adron | This looks like how I often use strtok when I'm a bit lazy. It will replace any trailing \r or \n with \0 - i.e. truncate the string. Also, the fgets loop will read in one line at a time, so you'll never have anything after the possible \r\n. | July 25, 2003, 7:30 PM |
Eibro | Bah, don't mind me. I didn't notice fgets would stop at a newline. | July 25, 2003, 7:41 PM |