#include <stdio.h> #include <stdlib.h> void main() { FILE *out1,*out2,*in; char c,str[50],temp; int i=0,j; if ( (out1=fopen("2.c","wb")) == NULL ) { perror("2.c"); exit( EXIT_FAILURE ); } if ( (out2=fopen("3.c","wb")) == NULL ) { perror("3.c"); exit( EXIT_FAILURE ); } c = getchar(); while( c != EOF ) { putchar(c); fputc(c,out1); c = getchar(); } fclose( out1 ); c = getchar(); c = getchar(); while( c != EOF ) { putchar(c); fputc(c,out2); c = getchar(); } fclose( out2 ); if ( (out1=fopen("2.c","rb")) == NULL ) { perror("2.c"); exit( EXIT_FAILURE ); } while ( feof( out1 ) == 0 ) { str[i] = fgetc( out1 ); i++; } fclose( out1 ); if ( (out2=fopen("3.c","rb")) == NULL ) { perror("3.c"); exit( EXIT_FAILURE ); } while ( feof( out2 ) == 0 ) { str[i] = fgetc( out2 ); i++; } fclose( out2 ); str[i] = '/0'; for ( i=0; i<strlen(str)-1; i++ ) { for ( j=0; j<strlen(str)-i-1; j++ ) { if ( str[j] >str[j+1] ) { temp = str[j]; str[j] = str[j+1]; str[j+1] = temp; } } } in = fopen( "4.c","wb" ); if( in == NULL ) { perror( "4.c" ); exit( EXIT_FAILURE ); } i = 0; while ( str[i] != '/0' ) { fputc(str[i],in); i++; } fputc(str[i],in); fclose( in ); in = fopen( "4.c","rb" ); if ( in == NULL ) { perror("4.c"); exit( EXIT_FAILURE ); } while( feof( in ) == 0 ) { c =fgetc( in ); putchar( c ); } fclose( in ); }