943,587 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3250
  • C RSS
Jan 5th, 2009
0

Unhandled exception and Access violation for every program

Expand Post »
I was working on some programs and now, no matter which one I run, I get an error like this: Unhandled exception at 0x00411be0 in program.exe: 0xC0000005: Access violation writing location 0x00130000.

Any ideas what is causing this or how I can fix it?
Reputation Points: 10
Solved Threads: 0
Light Poster
RenFromPenn is offline Offline
40 posts
since Dec 2008
Jan 5th, 2009
0

Re: Unhandled exception and Access violation for every program

Have you ran through the code till this occurred?
And actual code is nice, too.
Reputation Points: 888
Solved Threads: 114
Nearly a Posting Virtuoso
MosaicFuneral is offline Offline
1,270 posts
since Nov 2008
Jan 5th, 2009
0

Re: Unhandled exception and Access violation for every program

There are specifically two of them that are giving me this problem. The error appears as a pop-up. The debug tool, however, doesn't show an error.

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "string.h"
  4. void assemble(char*input, int num, char let, float flo);
  5.  
  6. int main()
  7. {
  8. char input[255];
  9. int num;
  10. char let;
  11. float flo;
  12.  
  13. printf("\nPlease enter an integer:\n");
  14. scanf("%d", &num);
  15. printf("\nPlease enter a character:\n");
  16. scanf("%c", &let);
  17. printf("\nPlease enter a floating point number:\n");
  18. scanf("%f", &flo);
  19.  
  20. assemble(input, num, let, flo);
  21. puts(input);
  22. return 0;
  23. }
  24.  
  25. void assemble(char *input, int num, char let, float flo)
  26. {
  27. sprintf(input, "%d, %c, %f", num, let, flo);
  28. }

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5.  
  6. int main()
  7. {
  8. #define MAXCHARS 300
  9. void convertToUpper(char[]);
  10. FILE *inFile;
  11. char fileName[25];
  12. char text[MAXCHARS];
  13.  
  14. printf("\nEnter a file name: ");
  15. gets(fileName);
  16. inFile = fopen(fileName, "r"); /*This opens the file */
  17. if (inFile == NULL) /*Checks that the file exists*/
  18.  
  19. {
  20. printf("\nThe file %s was not opened successfully.", fileName);
  21. printf("\nPlease check that you entered the file name correctly.\n");
  22. exit(1);
  23. }
  24. while (fscanf(inFile, "%s", text) !=EOF) /*Reads and displays the file*/
  25.  
  26. convertToUpper(text);
  27. printf("%s\n", text);
  28. fclose(inFile);
  29. return 0;
  30. }
  31.  
  32. void convertToUpper(char text[MAXCHARS])
  33. {
  34. int i;
  35. for(i = 0; text[i] != '0'; i++)
  36. text[i] = toupper(text[i]);
  37. }
Last edited by RenFromPenn; Jan 5th, 2009 at 1:05 pm.
Reputation Points: 10
Solved Threads: 0
Light Poster
RenFromPenn is offline Offline
40 posts
since Dec 2008
Jan 5th, 2009
0

Re: Unhandled exception and Access violation for every program

I managed to fix the first one, so now I just need help with the second program.
Reputation Points: 10
Solved Threads: 0
Light Poster
RenFromPenn is offline Offline
40 posts
since Dec 2008
Jan 5th, 2009
0

Re: Unhandled exception and Access violation for every program

You do not declare, or define functions in other functions.
Macros tend to go outside publicly.
Are you actually modifying text[] in convertToUpper()?
You loop and call a function, but only call printf() once, because you're missing something.
If the file didn't open, do you have to frantically escape, and not just pass over code with an if-else condition?
Reputation Points: 888
Solved Threads: 114
Nearly a Posting Virtuoso
MosaicFuneral is offline Offline
1,270 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Calling C++ function from C code
Next Thread in C Forum Timeline: Need examples of menu choices contected to linked lists





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC