I couldn't write what I had sone further, to my previous thread, as it was closed, as such had to create a new thread. Apologies for the same. I had modified my program with the following code to read each value of column 1 of my input file (*.ref) and create multiple Output files (*.brt) with name as the value at the column 1 of the input file. For each change in the value at column 1 of input file, a new output file (*.brt) should be created. But it doesn't seem to do what is required and when I run the application it gets hung. Could you please help me with the changes to the following code so that it works :- Code: ************************************************************** * Prog Language: VC++ * O.S.: Windows * Compiler/Assembler : Visual C++ 6.0 * Modifications : Take the output file names (*.brt) from column 1 of the data of the * input file (*.ref). New output file created for each change in the * value of the first column of the input file. **************************************************************/ void generate_brt_files(void) { char f_name[MAX_PATH]; FILE *ref_file; WIN32_FIND_DATA wfd; HANDLE find_handle; int seen_td_count = 0, cnt; char ch; char newline = 10; int commaCount; char this_td[3]; if (gen_brt_files) { if (!berth_step_dir[0]) { MessageBox(main_handle, "No location has been set for the berth stepping files.", "Error,,,", MB_ICONERROR | MB_OK); return; } memset(&wfd, 0, sizeof(WIN32_FIND_DATA)); wsprintf(f_name, "%sallsmf*.ref", berth_step_dir); if ((find_handle = FindFirstFile(f_name, &wfd)) == INVALID_HANDLE_VALUE) { MessageBox(main_handle, "No SMART berth stepping files found.", "Error...", MB_ICONERROR | MB_OK); return; } sfl_count = 0; memset(tds_ive_seen, 0, sizeof(tds_ive_seen)); memset(sfl, 0, sizeof(sfl)); while (1) { wsprintf(f_name, "%s%s", berth_step_dir, wfd.cFileName); if (ref_file = fopen(f_name, "rb")) { //Take the output file names (*.brt) from // column 1 of the data of the input file // (*.ref). New output file created for each // change in the value of the first column of // the input file. //memcpy(f_name, // wfd.cFileName,2); //this_td[2] = 0; f_name[12] = fgetc(ref_file); f_name[13] = fgetc(ref_file); f_name[14] = '.'; f_name[15] = 'r'; f_name[16] = 'e'; f_name[17] = 'f'; f_name[18] = 0; fgetc(ref_file); while(!feof(ref_file)) { ch = fgetc(ref_file); //brt_file = fopen(f_name, "a"); commaCount = 0; } while(ch != newline && commaCount < 4) { if (ch == ',') { commaCount ++; } else { //fputc(ch,brt_file); ch = fgetc(ref_file); } } //fputc(' ',brt_file); //flush rest of line while(ch != newline ) { ch = fgetc(ref_file); } //fclose(brt_file); //f_name[12]=fgetc(brt_file); //f_name[13]=fgetc(brt_file); //f_name[14]= '.'; //f_name[15]='b'; //f_name[12]='r'; //f_name[12]='t'; //f_name[12]=0; //fgetc(brt_file); //} //return 0 ; BOOL write_brt_file(int tis_ind) { FILE *brt_file; char f_name[MAX_PATH], buffer[100]; int cnt, last_rec; wsprintf(f_name, "%s%.2s.brt", berth_step_dir, tds_ive_seen[tis_ind].td_id); if (brt_file = fopen(f_name, "wb")) { last_rec = tds_ive_seen[tis_ind].sfl_rec_count + tds_ive_seen[tis_ind].sfl_ind; for (cnt = tds_ive_seen[tis_ind].sfl_ind; cnt < last_rec; cnt++) { wsprintf(buffer, "%c%.4s%.4s%.5s ", sfl[cnt].step_type, sfl[cnt].from_berth, sfl[cnt].to_berth, sfl[cnt].stanox); //fwrite(buffer, // 19, // 1, // brt_file); fputc(' ',brt_file); //fputc(ch,brt_file); } fclose(brt_file); } else { MessageBox(main_handle, "Unable to open file for writing", f_name, MB_ICONERROR | MB_OK); return FALSE; } //return TRUE; //} f_name[12]=fgetc(brt_file); f_name[13]=fgetc(brt_file); f_name[14]= '.'; f_name[15]='b'; f_name[16]='r'; f_name[17]='t'; f_name[18]=0; fgetc(brt_file); //} return 0 ; } Thanks a lot, Marconi.