Advertisement
CosmicFox33

Untitled

Dec 7th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <locale.h>
  6. int main()
  7. {
  8. setlocale(LC_ALL,"Russian");
  9. system("chcp 1251");
  10. system("cls");
  11. FILE *fp, *fp1;
  12. int i,j,b,flag=1;
  13. char name[81];
  14. char name1[81];
  15. char str[81], c;
  16. printf("enter the name of the input file with '.txt'\n");
  17. gets(name);
  18. if ((fp=fopen(name,"r"))==NULL)
  19. {
  20. printf("imposible to open file\n");
  21. getchar();
  22. return 0;
  23. }
  24.  
  25. printf("enter the name of the new file with '.txt'\n");
  26. gets(name1);
  27. fp1=fopen(name1,"w");
  28. while (!feof(fp))
  29. {
  30. if(fgets(str,80,fp))
  31. {
  32. i=0;
  33. j=0;
  34. b=strlen(str);
  35. //printf("%d",b);
  36. for(i=0;i<b-1;i++)
  37. {
  38. for(j=i+1;j<b;j++)
  39. {
  40. if(str[i]<str[j])
  41. {
  42. c=str[i];
  43. str[i]=str[j];
  44. str[j]=c;
  45. flag=0;
  46. }
  47. }
  48. }
  49. if(str[i]=='\n') str[i]='\0';
  50. fputs(str, fp1);
  51. fputs("\n", fp1);
  52. puts(str);
  53. }
  54. }
  55. if(flag)
  56. {
  57. fprintf(fp1, "File has not changed\n");
  58. printf("File has not changed\n");
  59. }
  60.  
  61. fclose(fp);
  62. fclose(fp1);
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement