Bonjour a tous,

Je débute en C et je doit faire un prog qui lit des lignes dans un fichier, trouver les chaines de caractères qui m'interessent et les écrire dans un autre fichier.

Voici mon code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main(){
	if( (cuID = (char**)malloc(CUID_TAB_SIZE * sizeof(*cuID) )) == NULL){
		printf("l'allocation de la mémoire a échoué!!\n");
		exit(-1);
	}
getCustomerID_String(buffer, cuID);
fprintf(sortie, "cuID[%d] = %s\n", j, cuID[j]);
}
 
void getCustomerID_String(char *_query, char **_cuID){
	if( (_cuID[i] = (char*)malloc(strlen(_query) + 1)) == NULL){
		printf("L'allocation de la mémoire a échoué!!\n");
		freemem(query, increment, pattern);
	}
	else{
		strcpy(_cuID[i], "ma chaine trouver");
}
Lors du realloc j'obtient une belle erreur de type :

*** glibc detected *** ./getCustomerID_String: realloc(): invalid pointer: 0xb7ee2278 ***
======= Backtrace: =========
/lib/i686/cmov/libc.so.6[0xb7df8624]
/lib/i686/cmov/libc.so.6(realloc+0x242)[0xb7dfcc82]
/lib/i686/cmov/libc.so.6(realloc+0x42)[0xb7dfca82]
./getCustomerID_String[0x80489ea]
./getCustomerID_String[0x8048c80]
/lib/i686/cmov/libc.so.6(__libc_start_main+0xe5)[0xb7da0455]
./getCustomerID_String[0x8048741]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 08:01 475103 /home/mathieu/
0804a000-0804b000 rw-p 00001000 08:01 475103 /home/mathieu
09ce6000-09d07000 rw-p 09ce6000 00:00 0 [heap]
b7d6f000-b7d7b000 r-xp 00000000 08:01 40883 /lib/libgcc_s.so.1
b7d7b000-b7d7c000 rw-p 0000b000 08:01 40883 /lib/libgcc_s.so.1
b7d89000-b7d8a000 rw-p b7d89000 00:00 0
b7d8a000-b7edf000 r-xp 00000000 08:01 50066 /lib/i686/cmov/libc-2.7.so
b7edf000-b7ee0000 r--p 00155000 08:01 50066 /lib/i686/cmov/libc-2.7.so
b7ee0000-b7ee2000 rw-p 00156000 08:01 50066 /lib/i686/cmov/libc-2.7.so
b7ee2000-b7ee5000 rw-p b7ee2000 00:00 0
b7ef0000-b7ef4000 rw-p b7ef0000 00:00 0
b7ef4000-b7ef5000 r-xp b7ef4000 00:00 0 [vdso]
b7ef5000-b7f0f000 r-xp 00000000 08:01 40882 /lib/ld-2.7.so
b7f0f000-b7f11000 rw-p 0001a000 08:01 40882 /lib/ld-2.7.so
bfbfc000-bfc11000 rw-p bffeb000 00:00 0 [stack]
Quelqu'un pourrait il me dire pourquoi?
Merci.