so for some reason my program likes to tell me "Could not open file.". it shouldn't be doing this, at least from what i can tell...here's my code:?? what am i doing wrong ?? i tried the debug function of Dev-C++ but it just freezes. everytime i run this, after telling me it can't open the file windows asks me to send them a report of my program crashing. =\Code:void SearchFiles(HWND hwnd, char *keywords) { FILE *fileptr, *xFileptr; char file[255] = {0}, data[255] = {0}; if((fileptr = fopen("dirlist.sby", "r")) == NULL) { MessageBox(NULL, "There was an error retrieving the directory listing.\n", "Error!", MB_OK | MB_ICONEXCLAMATION); } else { while(fgets(file, 255, fileptr) != '\0') { if((xFileptr = fopen(file, "r")) == NULL) { MessageBox(NULL, "Could not open file.\n", "Error!", MB_OK | MB_ICONEXCLAMATION); } else { while(fgets(data, 255, xFileptr) != '\0') { if(strstr(data, keywords) != NULL) { SendMessage(GetDlgItem(hwnd, ID_LISTOUT), LB_ADDSTRING, 0, (LPARAM)file); } } } fclose(xFileptr); } fclose(fileptr); } }
hah...so the problem was the method in which i was reading from the file. the fgets() function for some reason was messing it up. after adding/using this function:it worked :]Code:int fixgets(char input_array[], int length, FILE *file_name) { register int position=0; if (fgets(input_array,length,file_name) != NULL) { while(input_array[position] != 0) { if (input_array[position] < 32) input_array[position]=0; else ++position; } } /* The length of the string is returned. */ return position; }



LinkBack URL
About LinkBacks


