Hi, I've been working in a program for the school that use a recursive call to the function. The problem is that I have to use that function almost 86000 times, because I'm reading a dicctionary.
The problem occur in the ten or twelve call to the function and it appear in when I use a strlen to see the size o string.
That's why I think it's a problem with the memory.
I leave you the function to see if I'm doing something wrong.
Thanks -
void Insertar(Arbol *lista, char *numero, int posicion) {
-
pNodo nuevo, anterior;
-
char letra[10];
-
int trad;
-
-
fflush(stdout);
-
-
strncpy(letra, numero, 1);
-
trad = atoi(letra);
-
nuevo = (pNodo)malloc(sizeof(tipoNodo));
-
nuevo->numero = trad;
-
-
if (strlen(numero)== 1){
-
InsertoInterna(&nuevo->listaInterna, posicion);
-
}
-
-
if (ListaVacia(*lista)){
-
nuevo->siguiente = *lista;
-
*lista = nuevo;
-
if (strlen(numero)>1){
-
if ((int)numero[0]>=(int)numero[1]){
-
Insertar(&nuevo->izquierda, ++numero, posicion);
-
}
-
else{
-
Insertar(&nuevo->derecha, ++numero, posicion);
-
}
-
}
-
}else{
-
anterior = *lista;
-
while ((anterior->siguiente) && (anterior->numero != trad))
-
anterior = anterior->siguiente;
-
-
if (anterior->numero == trad){
-
if (strlen(numero)>1){
-
if ((int)numero[0]>=(int)numero[1])
-
Insertar(&anterior->izquierda, ++numero, posicion);
-
else
-
Insertar(&anterior->derecha, ++numero, posicion);
-
}
-
free(nuevo);
-
}
-
else{
-
nuevo->siguiente = anterior->siguiente;
-
anterior->siguiente = nuevo;
-
if (strlen(numero)>1){
-
if ((int)numero[0]>=(int)numero[1])
-
Insertar(&nuevo->izquierda, ++numero, posicion);
-
else
-
Insertar(&nuevo->derecha, ++numero, posicion);
-
}
-
}
-
}
-
-
return;
-
}
-
1 1587
if (strlen(numero)>1){
strlan() will crash your code if the pointer is null. Are you sure numero is not null?
If it's not null then, it will count characters until it finds a \0 regardless of how much memory has to be searched. Are you certain that you are not overrunning an array boundary?
I assume you have using your debugger to step through the calls so yo can see the state of your variables as things progress. You are using your debugger, right?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jois.de.vivre |
last post by:
Hi,
I have the following piece of code that is designed to help me add
debug traces to my program (I wanted to use purely C++ code, but the
only way I know how to do something like this is with...
|
by: kk |
last post by:
Hi all,
i didn't get output in the following code while compiling and executing
with g++ version 3.2.3 it doesn't allocate memory to pointer varaible
(x) in class B. and it gives correct output...
|
by: Materialised |
last post by:
I am having a problem with the following functions, I've been racking my
brains trying to figure out where I am going wrong. What I need to do is
return a formatted string with the current date and...
|
by: ajikoe |
last post by:
Hi,
I tried to follow the example in swig homepage.
I found error which I don't understand.
I use bcc32, I already include directory where my python.h exist in
bcc32.cfg.
/* File : example.c...
|
by: AlabiChin |
last post by:
Hello,
I noticed that when I dynamically create an array of chars, the
resulting size of the allocated memory block is larger by about 15
bytes than what I specified. Here is example code:
...
|
by: almurph |
last post by:
Hi everyone,
Can you help me please? I am having a problem with the
encryption/decryption of words with the Irish fada in them. The Irish
fada is like this: áéíóú/ÁÉÍÓÚ. It's kind of like the...
|
by: zaebos |
last post by:
hi, i have this code which is part of a main program, to email from
within the program a log file:
int MailIt (char *mailserver, char *emailto, char *emailfrom,
char *emailsubject, char...
|
by: dtschoepe |
last post by:
Hi,
I have a homework project I am working on, so be forwarned, I'm new to
C programming. But anyway, having some trouble with a memory
allocation issue related to a char * that is a variable...
|
by: weidongtom |
last post by:
Hi,
I've written the code that follows, and I use the function add_word(),
it seems to work fine
*before* increase_arrays() is called that uses realloc() to allocate
more memory to words. But...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |