Guest User

Untitled

a guest
Apr 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <stdlib.h>
  4. #define len 256          /*длина считываемой и записываемой строк*/
  5.  typedef
  6.   char str_20[20];
  7.  typedef
  8.   struct
  9.    {
  10.          str_20 w;
  11.          int n;
  12.    }rec;
  13.  str_20 w;
  14.  char s[len];                                /*объявили S*/
  15.  int check,k,i;
  16.  char c, endword;
  17.  void words(FILE *rfile)
  18.  {
  19.         int m=0;
  20.         int check;
  21.         char r[len];
  22.         char dr[len];
  23.         char p[len];
  24.         check=fclose(rfile);
  25.         rfile=("Helpfile.txt","r+");
  26.         while (!feof(rfile))
  27.         {
  28.                 fgets(r, len, rfile);
  29.                 if (strncpy(dr,r,strlen(w))==w)               //если есть, добавляем номер как строку
  30.                 {                                    /*преобразование позиции в строку*/
  31.                         strcat(r, " ");
  32.                         strcat(r, p);
  33.                         fseek(rfile, SEEK_SET+m, SEEK_SET);
  34.                         fputs(r, rfile);
  35.                         c=1;
  36.                         break;                                                //и выходим
  37.                 }
  38.                 m++;
  39.         }
  40.         if (!c)
  41.         {                           /*преобразование позиции в строку*/
  42.                 strcat(r, " ");
  43.                 strcat(r, p);
  44.                 fputs(r, rfile);
  45.         }
  46.         w[0]='\0';
  47.         endword=0;
  48.  }
  49.  void main(void)
  50.  {
  51.  
  52.         FILE *tfile;          /*объявили tfile*/
  53.         FILE *rfile=fopen("Helpfile.txt","w");      /*объявили rfile*/
  54.         tfile=fopen("File.txt","r");
  55.         if(tfile == NULL)
  56.                 {
  57.                         puts("Problems");
  58.                 }
  59.        
  60.         puts("Прошли))\n");
  61.         while (!feof(tfile))
  62.          {
  63.                 k++;
  64.                 fgets(s, len, tfile);
  65.                 for(i=1; i<strlen(s); i++)
  66.                   {     /*заглавные буквы      прописные буквы         цифры (a>0x40 && a<0x5B)||(a>0x60 && a<0x7B)||(a>0x30 && a<0x39)*/
  67.                          if (isalnum(s[i]))
  68.                                 c=1;
  69.  
  70.                         if (c!=0)
  71.                            {
  72.                                         strcat(w, s[i]);
  73.                                         if ((s[i+1] == ' ') || ( i+1 > strlen(s)))
  74.                                                 endword= 1;
  75.                            }
  76.  
  77.                  c=0;
  78.                  if (endword)
  79.                   words(rfile);
  80.                  c=0;
  81.                   }
  82.  
  83.          }
  84.         check=fclose(rfile);
  85.         rfile=("Helpfile.txt","r");
  86.         while (!feof(tfile))
  87.                 {
  88.                         fgets(s, len, tfile);
  89.                         printf("%s\n", s);
  90.                 }
  91.         fflush(stdin);
  92.         check=fclose(rfile);
  93.         check=remove("Helpfile.txt");
  94.  }
Add Comment
Please, Sign In to add comment