Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. 1) I open the input file
  2. 2) I read it
  3. 3) Store an 2D array
  4. 4) split into tokens
  5. 5) firslt strtok for "n" and store it
  6. 6) secondly strtok for ":" ignore it
  7. 7)and then strtok for "," and store it
  8. 8) I want to search a word for every single line (which I stored it step 5)
  9. 9) For searching I use strstr but I can't do it.
  10.  
  11. int main (){
  12.  
  13. FILE *fp;
  14. fp=fopen("C:\input.txt","r");
  15. char *name[10][10];
  16. char row[100];
  17. char *token,*tkn,*tk;
  18. int h=0, f=0, l=0;
  19. for(h=0;h<9;h++){
  20. for(f=0;f<9;f++)
  21. name[h][f]=NULL;
  22. }
  23. while(fgets(row,sizeof(row),fp)){
  24. token=strtok(row,"n");
  25. name[l][0] = strdup(token);
  26. //printf("%s",name[l][0]);
  27. tkn=strtok(token,":");
  28. tk=strtok(tkn,",");
  29. isim[l][1]=strdup(tk);
  30. if(strstr(name[l][1],name[l+1][0])==0 || strstr(name[l][1],name[l+2][0])==0 || strstr(name[l][1],name[l+3][0])==0){
  31.  
  32. }
  33. l++;
  34. }
  35.  
  36. fclose(fp);
  37. }
  38.  
  39. George :Math1,History2,Math2
  40. ELizabeth :Math2,Germany1,spanish1
  41. Adam :Germany1,History2,Math1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement