Advertisement
Guest User

Untitled

a guest
May 19th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <malloc.h>
  4.  
  5. void get_word(char *s, int *pos, char *w) {
  6. int n = strlen(s);
  7. int i = 0;
  8.  
  9. while (*pos < n && s[*pos] <= ' ') {
  10. ++*pos;
  11. }
  12.  
  13. while (*pos < n && s[*pos] > ' ') {
  14. w[i] = s[*pos];
  15. i++;
  16. ++*pos;
  17. }
  18. w[i] = '\0';
  19. }
  20.  
  21. void new_text(char *fname, char *str){
  22. FILE *F;
  23. long startpos,stoppos;
  24. char s[250],
  25. word[20];
  26.  
  27. int pos=0,n;
  28. F = fopen(fname, "r+");
  29. startpos=ftell(F);
  30. while ( fgets(s, 100, F) ) {
  31. puts(s);
  32. fseek(F,startpos,SEEK_SET);
  33. printf("%li\n",startpos);
  34.  
  35. char news[200]={""} ;
  36. n = strlen(s);
  37. while (pos < n) {
  38. get_word(s, &pos, word);
  39. if (strstr(word,str)!=NULL){
  40. strcat(news,word);
  41. strcat(news," ");
  42. // puts(news);
  43. }
  44. }
  45.  
  46. fprintf(F,"%s\n",news);
  47. startpos=ftell(F);
  48. fseek(F,startpos,SEEK_SET);
  49. pos=0;
  50. }
  51. }
  52.  
  53. int main() {
  54. char fname[20]="g.txt",
  55. STR[]="dv";
  56. //gets(fname);
  57.  
  58. new_text(fname,STR);
  59.  
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement