473,398 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

problem in memory -- strlen

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

Expand|Select|Wrap|Line Numbers
  1. void Insertar(Arbol *lista, char *numero, int posicion) {
  2.    pNodo nuevo, anterior;
  3.    char letra[10];
  4.    int trad;
  5.  
  6.    fflush(stdout);
  7.  
  8.    strncpy(letra, numero, 1);
  9.    trad = atoi(letra);
  10.    nuevo = (pNodo)malloc(sizeof(tipoNodo));
  11.    nuevo->numero = trad;
  12.  
  13.    if (strlen(numero)== 1){
  14.       InsertoInterna(&nuevo->listaInterna, posicion);
  15.    }
  16.  
  17.    if (ListaVacia(*lista)){
  18.       nuevo->siguiente = *lista;
  19.       *lista = nuevo;
  20.      if (strlen(numero)>1){
  21.          if ((int)numero[0]>=(int)numero[1]){
  22.             Insertar(&nuevo->izquierda, ++numero, posicion);
  23.          }
  24.          else{
  25.             Insertar(&nuevo->derecha, ++numero, posicion);
  26.          }
  27.       }
  28.    }else{
  29.         anterior = *lista;     
  30.         while ((anterior->siguiente) && (anterior->numero != trad))
  31.               anterior = anterior->siguiente;
  32.  
  33.       if (anterior->numero == trad){
  34.          if (strlen(numero)>1){
  35.             if ((int)numero[0]>=(int)numero[1])
  36.                Insertar(&anterior->izquierda, ++numero, posicion);
  37.             else
  38.                Insertar(&anterior->derecha, ++numero, posicion);
  39.          }
  40.          free(nuevo);
  41.       }
  42.       else{
  43.          nuevo->siguiente = anterior->siguiente;
  44.          anterior->siguiente = nuevo;
  45.          if (strlen(numero)>1){
  46.             if ((int)numero[0]>=(int)numero[1])
  47.                Insertar(&nuevo->izquierda, ++numero, posicion);
  48.             else
  49.                Insertar(&nuevo->derecha, ++numero, posicion);
  50.          }
  51.       }
  52.    }
  53.  
  54.    return;
  55. }
  56.  
Nov 14 '07 #1
1 1587
weaknessforcats
9,208 Expert Mod 8TB
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?
Nov 15 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
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...
4
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...
15
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...
2
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...
10
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: ...
2
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...
11
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...
17
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...
9
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.