I'm working on a program that would read the different lines from a file and start a thread for each one in which it would perform various operations depending on what's writter on the line, however I keep getting Segmentation Fault errors and I'm at a loss trying to solve it.
I tried to follow everything in this question thread: passing pointer char argument to function in thread
but it's still not working. The threaded function would be:
void *thread(void *arg)
{
char *buf = arg;
char *tok, *sp;
//extracting transaction type
tok = strtok_r(buf, " ", &sp);
//Branchement selon le type de transaction
switch(tok[0]){
...
}
and would be called by this part:
void* readTranslinkedINFO(char* nomFichier){
FILE *f;
char buffer[100];
pthread_t tid;
//Opening file
f = fopen(nomFichier, "rt");
if (f==NULL)
error(2, "readTrans: Erreur lors de l'ouverture du fichier.");
//read first line
fgets(buffer, 100, f);
//start a thread for each line
while(!feof(f)){
pthread_create(&tid, NULL, thread, buffer);
//reading next line
fgets(buffer, 100, f);
}
pthread_join(tid, NULL);
//closing file
fclose(f);
//Return
return NULL;
Any help would be very much appreciated Sorry if there are still a few french words here and there Thanks