c++ - Parse a file name from char * variable -


i have value in character pointer variable , value changed dynamically.

for e.g

one case:    char *ptr = sometext || abc.txt;  second case:    char *ptr = abc.txt || sometext; 

i need file name in variable. str = abc.txt

currently using code:

cstring str; char* lpsztotoken = stline.getbuffer(stline.getlength()); char* lpsztoken = strtok(lpsztotoken, "|"); while(lpsztoken != null) {    lpsztoken = strtok(null, "|");    str = lpsztoken; } 

but working in first case: need genric code run in both case idea? thanks,

my c rusty, why not like:

char* fname = strtok( filenames, "|"); while (fname != null) {     // file here..     processfile( fname);                  fname = strtok( null, "|");         // next. } 

also, hungarian notation horrible way program. conceals & obfuscates meaning, rendering clear , simple problems opaque & ugly. see how readable example is, compared gack supplied?

your instructor (and petzold) unfortunately mistaken teaching you. suggest writing "literate" code instead.

see:


Comments