By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,953 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,953 IT Pros & Developers. It's quick & easy.

Error - An unhandled win32 exception occured [472]

P: 1
Hi all, I'm new to C programming. I'm running the code in Visual Studio where it will read a text file and after reading the file using struct. It will filter the data based on the if else condition below. I'm getting the "Error - An unhandled win32 exception occured [472]" and i think it should be something to do with the string "i".

I didn't post the other code but please let me know if you need it.

Sample of data file:
9001:0002:9003:0021:CLS
0001:0010:0003:0021:CLS


Expand|Select|Wrap|Line Numbers
  1. for (i = 0; i < count; i++){
  2. isValid = true;
  3. if (array[i].src < 1 || array[i].src > 1024){
  4. isValid = false;
  5. }
  6. else
  7. if (array[i].dest < 1 || array[i].dest > 1024){
  8. isValid = false;
  9. }
  10. else
  11. if (array[i].type < 1 || array[i].type > 10){
  12. isValid = false;
  13. }
  14. else
  15. if (array[i].port < 1 || array[i].port > 1024){
  16. isValid = false;
  17. }
  18. else
  19. if (strlen(array[i].data) < 1 || strlen(array[i].data) > 50)
  20. isValid = false;
  21.  
  22. //if meets the condition above writes to correct txt file
  23. if (isValid){
  24. n1++;
  25. fprintf(outFile, "%04d:%04d:%04d:%04d %s \n",
  26.     array[i].src,
  27.     array[i].dest,
  28.     array[i].type,
  29.     array[i].port,
  30.     array[i].data
  31.     );
  32. printf("%d:%d:%d:%d %s \n");
  33. }
  34. else
  35. {
  36. //if do not meet the condition above writes to correct txt file
  37. n2++;
  38. fprintf(errorFile, "%04d:%04d:%04d:%04d %s \n",
  39.     array[i].src,
  40.     array[i].dest,
  41.     array[i].type,
  42.     array[i].port,
  43.     array[i].data
  44.     );
  45. printf("%d:%d:%d:%d %s \n");
  46. }
  47.     }
  48. fclose(errorFile); //close error output file once done
  49. fclose(outFile); //close correct output file once done
  50. return 0;
  51. }
  52.  
Dec 9 '15 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
Have you stepped through this with the debugger?

You need to be sure the array is correct. There's a strlen in there and that means a \0 must end the array and not [i].

Personally, I would write a small driver with a hard-coded array I know is accurate and then step through this logic.
Dec 9 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.