reading error
-
I got this error message when I debug: Unhandled exception at 0x77a915de in MSW_Vib_Model.exe: 0x00000000: The operation completed successfully. from these code segments: // ifl=0; do { { // fscanf_s(f_ptr_seed_inf,"%lf %lf %s\n",&sd_dis[ifl],&time_onset[ifl], ftitle[ifl].GetBuffer(MAX_PATH)); ftitle[ifl].ReleaseBuffer(); } ifl += 1; } while (!feof(f_ptr_seed_inf)&&(ifl<120)); nfile=ifl; // This is my input file: 4171.000 0.28600 ECO61_4171_Hole1_seeds.txt 4157.000 0.24600 ECO61_4157_Hole2_seeds.txt Please help me.
-
I got this error message when I debug: Unhandled exception at 0x77a915de in MSW_Vib_Model.exe: 0x00000000: The operation completed successfully. from these code segments: // ifl=0; do { { // fscanf_s(f_ptr_seed_inf,"%lf %lf %s\n",&sd_dis[ifl],&time_onset[ifl], ftitle[ifl].GetBuffer(MAX_PATH)); ftitle[ifl].ReleaseBuffer(); } ifl += 1; } while (!feof(f_ptr_seed_inf)&&(ifl<120)); nfile=ifl; // This is my input file: 4171.000 0.28600 ECO61_4171_Hole1_seeds.txt 4157.000 0.24600 ECO61_4157_Hole2_seeds.txt Please help me.
The problem is readying the string with
fscanf_s
. If you replacefscanf_s
withfscanf
, you will notice that it works without errors. The _s (secure) versions of the C-Runtime requires that the size of the buffer be known and this is validated by the function. So you need to pass in the size of the string as an argument following the actual string buffer as shown -fscanf_s(f_ptr_seed_inf,"%lf %lf %s\n",&sd_dis[ifl],&time_onset[ifl], ftitle[ifl].GetBuffer(MAX_PATH), MAX_PATH);
Here is an excerpt from the documentation for
scanf_s
-Unlike scanf and wscanf, scanf_s and wscanf_s require the buffer size to be specified for all input parameters of type c, C, s, S, or string control sets that are enclosed in []. The buffer size in characters is passed as an additional parameter immediately following the pointer to the buffer or variable. For example, if you are reading a string, the buffer size for that string is passed as follows: char s[10]; scanf_s("%9s", s, _countof(s)); // buffer size is 10, width specification is 9
«_Superman_» _I love work. It gives me something to do between weekends.