Unhandled exception and Access violation for every program

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2008
Posts: 40
Reputation: RenFromPenn is an unknown quantity at this point 
Solved Threads: 0
RenFromPenn RenFromPenn is offline Offline
Light Poster

Unhandled exception and Access violation for every program

 
0
  #1
Jan 5th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 960
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: Unhandled exception and Access violation for every program

 
0
  #2
Jan 5th, 2009
Have you ran through the code till this occurred?
And actual code is nice, too.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 40
Reputation: RenFromPenn is an unknown quantity at this point 
Solved Threads: 0
RenFromPenn RenFromPenn is offline Offline
Light Poster

Re: Unhandled exception and Access violation for every program

 
0
  #3
Jan 5th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 40
Reputation: RenFromPenn is an unknown quantity at this point 
Solved Threads: 0
RenFromPenn RenFromPenn is offline Offline
Light Poster

Re: Unhandled exception and Access violation for every program

 
0
  #4
Jan 5th, 2009
I managed to fix the first one, so now I just need help with the second program.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 960
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

Re: Unhandled exception and Access violation for every program

 
0
  #5
Jan 5th, 2009
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?
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC