Forum Replies Created
Viewing 1 post (of 1 total)
- AuthorPosts
- September 3, 2009 at 4:41 pm in reply to: Read 1st col vals of i/pfile;create o/p fl for each diff val #3607GarnetHuynhParticipant
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 :-
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215<br />************************************************************************<br />* Prog Language: VC++<br />* O.S.: Windows<br />* Compiler/Assembler : Visual C++ 6.0<br />* Modifications : Take the output file names (*.brt) from<br />* column 1 of the data of the input file<br />* (*.ref). New output file created for each<br />* change in the value of the first column of<br />* the input file.<br />*************************************************************************/<br /><br />void generate_brt_files(void)<br />{<br /><br />char f_name[MAX_PATH];<br />FILE *ref_file;<br />WIN32_FIND_DATA wfd;<br />HANDLE find_handle;<br />int seen_td_count = 0,<br />cnt;<br />char ch;<br />char newline = 10;<br />int commaCount;<br /><br />char this_td[3];<br /><br /><br />if (gen_brt_files)<br />{<br />if (!berth_step_dir[0])<br />{<br />MessageBox(main_handle, "No location has been set<br />for the berth stepping files.", "Error,,,",<br />MB_ICONERROR | MB_OK);<br />return;<br />}<br /><br />memset(&wfd, 0, sizeof(WIN32_FIND_DATA));<br /><br /><br />wsprintf(f_name, "%sallsmf*.ref",<br />berth_step_dir);<br /><br />if ((find_handle = FindFirstFile(f_name, &wfd)) == INVALID_HANDLE_VALUE)<br />{<br />MessageBox(main_handle, "No SMART berth<br />stepping files found.", "Error...",<br />MB_ICONERROR | MB_OK);<br />return;<br />}<br /><br />sfl_count = 0;<br /><br />memset(tds_ive_seen,<br />0,<br />sizeof(tds_ive_seen));<br /><br />memset(sfl,<br />0,<br />sizeof(sfl));<br /><br />while (1)<br />{<br /><br />wsprintf(f_name,<br />"%s%s",<br />berth_step_dir,<br />wfd.cFileName);<br /><br />if (ref_file = fopen(f_name, "rb"))<br /><br />{<br /><br />//Take the output file names (*.brt) from<br />// column 1 of the data of the input file<br />// (*.ref). New output file created for each<br />// change in the value of the first column of<br />// the input file.<br /><br />//memcpy(f_name,<br />// wfd.cFileName,2);<br />//this_td[2] = 0;<br /><br /><br />f_name[12] = fgetc(ref_file);<br />f_name[13] = fgetc(ref_file);<br />f_name[14] = '.';<br />f_name[15] = 'r';<br />f_name[16] = 'e';<br />f_name[17] = 'f';<br />f_name[18] = 0;<br /><br />fgetc(ref_file);<br /><br /><br />while(!feof(ref_file))<br /><br />{<br />ch = fgetc(ref_file);<br />//brt_file = fopen(f_name, "a");<br />commaCount = 0;<br />}<br /><br />while(ch != newline && commaCount < 4)<br />{<br />if (ch == ',')<br />{<br />commaCount ++;<br />}<br /><br />else<br />{<br />//fputc(ch,brt_file);<br />ch = fgetc(ref_file);<br />}<br />}<br /><br /><br />//fputc(' ',brt_file);<br /><br />//flush rest of line<br />while(ch != newline )<br />{<br />ch = fgetc(ref_file);<br />}<br /><br />//fclose(brt_file);<br /><br />//f_name[12]=fgetc(brt_file);<br />//f_name[13]=fgetc(brt_file);<br />//f_name[14]= '.';<br />//f_name[15]='b';<br />//f_name[12]='r';<br />//f_name[12]='t';<br />//f_name[12]=0;<br />//fgetc(brt_file);<br />//}<br /><br /><br />//return 0 ;<br /><br /><br /><br />BOOL write_brt_file(int tis_ind)<br />{<br /><br />FILE *brt_file;<br />char f_name[MAX_PATH],<br />buffer[100];<br />int cnt,<br />last_rec;<br /><br /><br />wsprintf(f_name,<br />"%s%.2s.brt",<br />berth_step_dir,<br />tds_ive_seen[tis_ind].td_id);<br /><br />if (brt_file = fopen(f_name, "wb"))<br />{<br />last_rec = tds_ive_seen[tis_ind].sfl_rec_count + tds_ive_seen[tis_ind].sfl_ind;<br />for (cnt = tds_ive_seen[tis_ind].sfl_ind; cnt < last_rec; cnt++)<br />{<br /><br />wsprintf(buffer,<br />"%c%.4s%.4s%.5s ",<br />sfl[cnt].step_type,<br />sfl[cnt].from_berth,<br />sfl[cnt].to_berth,<br />sfl[cnt].stanox);<br /><br />//fwrite(buffer,<br />// 19,<br />// 1,<br />// brt_file);<br /><br /><br />fputc(' ',brt_file);<br /><br />//fputc(ch,brt_file);<br /><br />}<br /><br />fclose(brt_file);<br /><br />}<br /><br />else<br /><br />{<br />MessageBox(main_handle, "Unable to open file for writing", f_name,<br />MB_ICONERROR | MB_OK);<br /><br />return FALSE;<br />}<br /><br />//return TRUE;<br />//}<br /><br />f_name[12]=fgetc(brt_file);<br />f_name[13]=fgetc(brt_file);<br />f_name[14]= '.';<br />f_name[15]='b';<br />f_name[16]='r';<br />f_name[17]='t';<br />f_name[18]=0;<br />fgetc(brt_file);<br />//}<br /><br />return 0 ;<br /><br />}<br /><br />Thanks a lot,
Marconi. - AuthorPosts
Viewing 1 post (of 1 total)