Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. //удаление слолва из файла
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <stdbool.h>
  5. bool letter(char a)
  6. {
  7. if ((a>='a' && a<='z') || (a>='A' && a<='Z'))
  8. return true;
  9. else return false;
  10. }
  11. int main() {
  12. FILE* f;
  13. if(!(f=fopen("/Users/ilabockov/Desktop/Каринка/aaa.txt","r+")))
  14. {
  15. printf ("error opening file");
  16. return 1;
  17. }
  18. char ch;
  19. int count=1;
  20. int size;
  21. int flag=0;
  22.  
  23. while (((ch=getc(f))!=EOF))
  24. {
  25. if (letter(ch)==false)
  26. {
  27. if(count==5){
  28. flag=1;
  29. break;
  30. }
  31. ch=getc(f);
  32. if (letter(ch)==true)
  33. {
  34. count ++;
  35. }
  36.  
  37. }
  38. if(flag==1){
  39. break;
  40. }
  41. if (count==5)
  42. {
  43. size++;
  44. printf ("%c",ch);
  45. }
  46. }
  47. fseek(f,-1,SEEK_CUR);
  48. int minussize=(-size)-1;
  49. while((ch=getc(f))!=EOF){
  50. fseek(f,minussize,SEEK_CUR);
  51. fputc(ch, f);
  52. fseek(f,size,SEEK_CUR);
  53. }
  54. for(int i=0;i<=size;++i){
  55. fputc('\0',f);
  56. }
  57. printf ("%d\n",count);
  58. fclose (f);
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement