Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <malloc.h>
- void get_word(char *s, int *pos, char *w) {
- int n = strlen(s);
- int i = 0;
- while (*pos < n && s[*pos] <= ' ') {
- ++*pos;
- }
- while (*pos < n && s[*pos] > ' ') {
- w[i] = s[*pos];
- i++;
- ++*pos;
- }
- w[i] = '\0';
- }
- void new_text(char *fname, char *str){
- FILE *F;
- long startpos,stoppos;
- char s[250],
- word[20];
- int pos=0,n;
- F = fopen(fname, "r+");
- startpos=ftell(F);
- while ( fgets(s, 100, F) ) {
- puts(s);
- fseek(F,startpos,SEEK_SET);
- printf("%li\n",startpos);
- char news[200]={""} ;
- n = strlen(s);
- while (pos < n) {
- get_word(s, &pos, word);
- if (strstr(word,str)!=NULL){
- strcat(news,word);
- strcat(news," ");
- // puts(news);
- }
- }
- fprintf(F,"%s\n",news);
- startpos=ftell(F);
- fseek(F,startpos,SEEK_SET);
- pos=0;
- }
- }
- int main() {
- char fname[20]="g.txt",
- STR[]="dv";
- //gets(fname);
- new_text(fname,STR);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement