title: Check if string is already printed
body: <p>I am trying to build a C program that reads contents from a file, tokenize the contents and categorize the tokens at the same time, copying the tokens into an array of temp.My goal is to print the tokens that are not previously printed. In other words if the token has been already printed, skip this token from printing. My way to achieve this is to create a function that checks if the token has appeared in my array temp. If the token appeared in the array temp, then return 1 else return -1. My problem is, the function does not work, isAdded is always not 1. Thus, it still prints the previously printed tokens. I traced my code, and it seems correct to me. I don't know why it always return -1.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>char *temp[MAX]; /*globally declared*/
  
  
  void tokenize(FILE *input){
  
  char *token;
  int k=0;
  
  char word[1000];
  while(!feof(input)){
      fgets(word,1000,input);
      token = strtok(word, " \t\n");
          while(token!=NULL){                     
              if(isAdded(token)!=1){
                  if(isKeyword(token)==1){
                      printf("%s, %s\n", token, token);
                  }
                  temp[k] = (char*)malloc(strlen(token)+1);
                  strcpy(temp[k],token);
                  k++;
              }
              token= strtok(NULL, " \t\n");
          }
  }
  }
  
  
  int isAdded(char *token){
          int i=0;
          while(temp[i]!=NULL){
              if(strcmp(temp[i],token)==0){
                  return 1;
                  break;
              }
              i++;
              return -1;
          }
  }
  
  
  int isKeyword(char *token){
      int i=0;
          while(resWord[i]!=NULL){
              if(strcmp(resWord[i],token)==0){
                  return 1;
                  break;
              }
              i++;
          }
  }
  </code></pre>