C code only compiles once and then closes

Asked

Viewed 57 times

1

I have a code that I am writing in C, and then a problem is constantly happening. I don’t know if it has anything to do with memory allocation.

I have a function:

struct elementodos interpretar(char* element){

    struct elementodos separado;
    char** pontpont = (char**)malloc(200 * sizeof(char*));

    int i, a, cont, tem[100], cdd, dll, obs,conta,jubs, xevs;
    int mult[100];
    char* brasil = (char*)malloc(100 * sizeof(char));
    char* bahea = (char*)malloc(100 * sizeof(char));
    char** elemfim = (char**)malloc(100 * sizeof(char*));
    char* zoia = (char*)malloc(100 * sizeof(char));

...

for (i=0;i<cont;i++){

        separado.multidor[i]=mult[i];
        separado.cadaum[i]=elemfim[i];

    }
    separado.numero=cont;

return separado;
}

All elements are defined:

struct elementodos{
    int multidor[100];
    int numero;
    char** cadaum[100];
};

So I call the function on my main:

int main(){
struct elementodos a; 
...

a= interpretar(b);
return 0;

The problem is that it performs perfectly the first time, crash at the command prompt.

Ps: Returns no error.

When I run the Bugger only thing that appears and:

In _Jv_RegisterClasses () ()
In _Jv_RegisterClasses () ()
[Inferior 1 (process 4184) exited normally]
Debugger finished with status 0
  • Have you tried using GDB to run line by line? Anyway some things seem strange to me, he seems to take advantage of memory junk to run in the first, and does not have the same luck in the second onwards. And this code is also not complete, post all the code, mainly where you assign values to cont,mult and the elemfim.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.