realloc(): invalid next size
- From: "solanki.chandrakant@xxxxxxxxx" <Solanki.Chandrakant@xxxxxxxxx>
- Date: 30 Oct 2006 23:06:51 -0800
hi
i have fedora linux 4 and i have simple realloc program which i am
included here... plz help me to overcome the realloc to pointer to
character variable. The program working 2 times but more than 2 times
it gives error : realloc() - invalid next size.
#include <stdio.h>
#include <stdlib.h>
char *source = '\0';
int strlens( char *name ){ /* find the length of given string */
int k = 0;
for( ; name[k] != '\0'; k++ ) ;
return k;
}
int strcats( char *name, int start ) { /* concatenate the string */
int l = strlens( name );
int i = start, j = 0, z;
if( NULL == ( source = realloc ( source, l * sizeof( char ) + 1 )) )
fprintf( stderr, "error: realloc failed.\n" );
l += start;
while( i != l )
source[i++] = name[j++];
source[i++] = '!';
return i;
}
int main( void ) { /* main function */
int length = 0, k;
char *string = "abcdefghijklmnopqrstuvwxyz";
for( k = 0; k < 5; k++ ) {
length = strcats( string, length );
fprintf( stderr, "Length : %d\tString : %s\n", length, source );
}
return 0;
}
Chandrakant
.
- Follow-Ups:
- Re: realloc(): invalid next size
- From: Herbert Rosenau
- Re: realloc(): invalid next size
- From: Richard Heathfield
- Re: realloc(): invalid next size
- Prev by Date: Re: how to design an testing example
- Next by Date: Re: realloc(): invalid next size
- Previous by thread: how to design an testing example
- Next by thread: Re: realloc(): invalid next size
- Index(es):
Relevant Pages
|
|