Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <locale.h>
- int main()
- {
- setlocale(LC_ALL,"Russian");
- system("chcp 1251");
- system("cls");
- FILE *fp, *fp1;
- int i,j,b,flag=1;
- char name[81];
- char name1[81];
- char str[81], c;
- printf("enter the name of the input file with '.txt'\n");
- gets(name);
- if ((fp=fopen(name,"r"))==NULL)
- {
- printf("imposible to open file\n");
- getchar();
- return 0;
- }
- printf("enter the name of the new file with '.txt'\n");
- gets(name1);
- fp1=fopen(name1,"w");
- while (!feof(fp))
- {
- if(fgets(str,80,fp))
- {
- i=0;
- j=0;
- b=strlen(str);
- //printf("%d",b);
- for(i=0;i<b-1;i++)
- {
- for(j=i+1;j<b;j++)
- {
- if((str[i]>='0'&&str[i]<='9')&&(str[j]>='0'&&str[j]<='9')&&str[i]<str[j])
- {
- c=str[i];
- str[i]=str[j];
- str[j]=c;
- flag=0;
- }
- }
- }
- if(str[i]=='\n') str[i]='\0';
- fputs(str, fp1);
- fputs("\n", fp1);
- puts(str);
- }
- }
- if(flag)
- {
- fprintf(fp1, "File has not changed\n");
- printf("File has not changed\n");
- }
- fclose(fp);
- fclose(fp1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement