strtok et strsep

APPLOLIVIER

Membre confirmé
9 Octobre 2006
93
5
55
je comprends pas qd je mets strtok cela marche tres bien mais qd j'utillise strsep j'ai un bo segmentation fault
je vois pas d'ou vient le probleme ( j'utilise xcode)

#include <stdio.h>
#include <string.h>

int main (int argc, const char * argv[])
{
const char delim[]=" \'";
char buffer[1024];
sprintf(buffer,"%s/RETRIEVE",argv[1]);
FILE *fichier=fopen(buffer,"r");
memset(buffer,0,1024);
fgets(buffer,1024,fichier);
while(!feof(fichier))
{
puts(strsep(&buffer,delim));
fgets(buffer,1024,fichier);
}
fclose(fichier);
return 0;
}
 
strsep(char **stringp, const char *delim);
strtok(char *str, const char *sep);

:siffle: bon je pense que tu le vois la le probleme

Bloc de code:
        FILE *fp = fopen(fileName,"r");
        
        if(fp != NULL)
        {
            int res = 0;
            res = fseek(fp,0,SEEK_END);
            res = ftell(fp);
            rewind(fp);
            unsigned char *buff = (unsigned char *)calloc(1,res);
            
            if (buff != NULL)
            {
                if(fread(buff,res,1,fp) > 0)
                    printf("%s",buff);
                
                free(buff);
            }    
            fclose(fp);
        }
 
[START RECAP FOR NEWBS]

char buff[size_t];

NON:

*buff pointer on buff[]

POSSIBLE:(pas merveilleux
**buff handle on buff[]

DONC ==>

POSSIBLE:
strsep(char **stringp, const char *delim);

NON:
strtok(char *str, const char *sep);

[/END RECAP FOR NEWBS]
 
[START RECAP FOR NEWBS]

char buff[size_t];

NON:

*buff pointer on buff[]

POSSIBLE:(pas merveilleux
**buff handle on buff[]

DONC ==>

POSSIBLE:
strsep(char **stringp, const char *delim);

NON:
strtok(char *str, const char *sep);

[/END RECAP FOR NEWBS]
merci maintenant cela marche j'avais pas compris que je pouvais pas passer l'adresse de mon buffer