mercredi 28 décembre 2016

Segmentation fault using relational operators in if condidtion

The first if condition leads to a segmentation fault. I can't really comprehend why, since I use similar if clauses with relational operators elsewhere. Thanks for your help in advance.

int foo(char *str1,char **str2, char **str3)
{
  char *token1;
  char *token2;
  char *token = strtok(str1, "\"");
  int spaces = strcmp(token,"  ");
  int parenthesis = strcmp("{",token);
  if((name_a == NULL) || ((spaces != 0) && (parente != 0))) 
  {
    printf("ERR.\n");
    return 0;
  } 
  token = strtok(NULL, "\"");
  if(token == NULL)
  {  
    printf("2ERR\n");
    return 0;
  }
  token1= strtok(NULL, "\"");
  if(token1 == NULL || strcmp(token1," -> ") != 0)
  {
    printf("3ERR\n");
    return 0;
  }
  token2 = strtok(NULL, "\"");
  return 1;
  }

Aucun commentaire:

Enregistrer un commentaire