Jump to content
  • Advertisement
Sign in to follow this  

Access Violation

This topic is 1115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello dear users! I have a problem with my code, and I don't really know where to find it, and what did I do wrong. It's a simple code, with a structure, a linked list, and I want to read a txt into my list, but it always stops running, and shuts down with error. I use CodeBlocks, there are no errors or warnings, but it says this: Process terminated with status -1073741819 (or sometimes -255). Here is the problemic part:
typedef struct  jatekos {        
    int mezszam;
    char nev[10+1];
    int loves;
    int gol;
    int perc;
    int lap;
    struct jatekos *kov;
    } jatekos ;

void add( jatekos  *head, int d, char *s)                    /function to fill the list from the back/
     jatekos  *uj=(jatekos*)malloc(si zeof(jatekos));
    jatekos *akt=head;
    while(akt->kov!=NULL)                   /I think the problem is somewhere here/
    strcpy(uj->nev, s);

I always put it in Visual Studio i got this error: "Unhandled exception at 0x010E146E in CA.exe: 0x00005: Access violation reading location xy." And it says there are errors with reading characters of string.
I really hope, that you can help me with this, because i tried to solve it in many ways, and yet nothing happened. Thank you!

Edited by frob
Restored portions, we don't have history for tags or titles.

Share this post

Link to post
Share on other sites

How do you add one the first time? (ie head == NULL, so "akt->kov" doesn't exist).

Another thing to check is whether strlen(s) <= 10.


Note that it's a heck faster if you pass the last element into the function instead of the head (eliminating the search).

Also return the address of the newly allocated structure to the caller, so it can store it as new "last element".


You should be able to find the precise problem in a debugger. It's worth finding out how such a thing works if you don't know.

Share this post

Link to post
Share on other sites

As mentioned, please do not vandalize your posts once you find the solution.


Instead please post what your solution was for those who come after you. 


Giving due credit, Swiftcoder reverted the body of the post, I provided a better title than "solved" since that isn't automatically recovered.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!