if (chain==NULL) return -1;
char string[] = "test z ...."; const int _z = 'z'; int resultForward, resultReverse; char *pdest = strchr( string, _z ); resultForward = (int)(pdest - string + 1); pdest = strrchr( string, _z ); resultReverse = (int)(pdest - string + 1);
#include <stdio.h> #include <string.h> int strwisfc(const char* chain, const char c) { unsigned int i = 0; for (i = 0; i < strlen(chain); i++) if (chain[i] == c) return i; return -1; } int strwislc(const char* chain, const char c) { int i = 0; for (i = strlen(chain) - 1; i >= 0; i--) if (chain[i] == c) return i; return -1; } int main(void) { const char* test1 = "ztotoz"; const char* test2 = "not found"; printf ("%d ?= %d\n", strwisfc(test1, 'z'), strwislc(test1, 'z')); printf ("%d ?= %d\n", strwisfc(test2, 'z'), strwislc(test2, 'z')); return 0; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionj'ai pas eu de Warnings même en -Wall
j'avoue que je n'arrive pas à configurer correctement GDB
j'ai bien isolé toutes les parties du code une par une et c'est la seule qui me faisait planter
Finalement j'ai lancé GDB directement en commande et il me sort un "Segmentation fault".
while (strwisfs(ln, endingChar)!=0){ line = (int)ftell(file); ln = fgetln(file); printf("Line : '%s'\n", ln); if (strwisfc(ln, '\\')!=-1){ endLbl = line + strwisfc(ln, ' '); addBloc(line, &newBloc); newBloc->labelEnd = endLbl-1; newBloc->commentStart = endLbl + 1; if (strwislc(ln, '\\') == strwisfc(ln, '\\')) { //Plantage ici <------ #if 0 if (strcmp(chain->chain,"///")==0){ newBloc->commentEnd = (int)ftell(file); } else if(strcmp(chain->chain,"/**")==0) { newBloc->commentEnd = strwislc(ln, '\\')-2; } else { for (ln = fgetln(file);strwisfc(ln, '\\')!=-1 || strwisfs(ln, "*/")!=-1;ln = fgetln(file)); newBloc->commentEnd = (int)ftell(file) + strwisfc(ln, '\\') - 1; } #endif } else { fprintf(stderr, "Error : two comments in-lined, feedBlocks() can't manage!"); } } }
(gdb) bt #0 0x00401c49 in ?? () #1 0x00401861 in ?? () #2 0x00401953 in ?? () #3 0x00401468 in ?? () #4 0x004010b9 in ?? () #5 0x00401284 in ?? () #6 0x750d33aa in KERNEL32!BaseCleanupAppcompatCacheSupport () from C:\Windows\syswow64\kernel32.dll #7 0x0028ffd4 in ?? () #8 0x77639ef2 in ntdll!RtlpNtSetValueKey () from C:\Windows\system32\ntdll.dll #9 0x7efde000 in ?? () #10 0x77639ec5 in ntdll!RtlpNtSetValueKey () from C:\Windows\system32\ntdll.dll #11 0x0040126c in ?? () #12 0x00000000 in ?? ()