#include <stdio.h>
typedef struct Personal
{
char name[ 50 ] ;
int ten;
} Kojin;
// prototype
void input( Kojin * p) ;
void output( Kojin * p) ;
void data_sort( Kojin * p) ;
int main( void )
{
Kojin data[ 5 ] ;
input( data) ;
data_sort( data) ;
output( data) ;
return 0 ;
}
void input( Kojin * p)
{
FILE
* fp
= fopen ( "data.txt" , "r" ) ; for ( int i = 0 ; i < 5 ; ++ i, p++ )
fscanf ( fp
, "%s %d" , p
-> name
, & p
-> ten
) ; }
void output( Kojin * p)
{
FILE
* fp
= fopen ( "result.txt" , "w" ) ; for ( int i = 0 ; i < 5 ; ++ i, p++ )
fprintf ( fp
, "%s %d\n " , p
-> name
, p
-> ten
) ; }
void data_sort( Kojin * p)
{
Kojin t;
for ( int i = 0 ; i < 5 ; ++ i)
for ( int j = i + 1 ; j < 5 ; ++ j)
if ( p[ i] .ten > p[ j] .ten )
{
t = p[ i] ;
p[ i] = p[ j] ;
p[ j] = t;
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CnR5cGVkZWYgc3RydWN0IFBlcnNvbmFsCnsKICAgIGNoYXIgbmFtZVs1MF07CiAgICBpbnQgdGVuOwp9IEtvamluOwoKLy8gcHJvdG90eXBlCnZvaWQgaW5wdXQoS29qaW4gKnApOwp2b2lkIG91dHB1dChLb2ppbiAqcCk7CnZvaWQgZGF0YV9zb3J0KEtvamluICpwKTsKCmludCBtYWluKHZvaWQpCnsKICAgIEtvamluIGRhdGFbNV07CiAgICBpbnB1dChkYXRhKTsKICAgIGRhdGFfc29ydChkYXRhKTsKICAgIG91dHB1dChkYXRhKTsKICAgIHJldHVybiAwOwp9CnZvaWQgaW5wdXQoS29qaW4gKnApCnsKICAgIEZJTEUgKmZwID0gZm9wZW4oImRhdGEudHh0IiwgInIiKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgNTsgKytpLCBwKyspCiAgICAgICAgZnNjYW5mKGZwLCAiJXMgJWQiLCBwLT5uYW1lLCAmcC0+dGVuKTsKICAgIGZjbG9zZShmcCk7Cn0KCnZvaWQgb3V0cHV0KEtvamluICpwKQp7CiAgICBGSUxFICpmcCA9IGZvcGVuKCJyZXN1bHQudHh0IiwgInciKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgNTsgKytpLCBwKyspCiAgICAgICAgZnByaW50ZihmcCwgIiVzICVkXG4iLCBwLT5uYW1lLCBwLT50ZW4pOwogICAgZmNsb3NlKGZwKTsKfQoKdm9pZCBkYXRhX3NvcnQoS29qaW4gKnApCnsKICAgIEtvamluIHQ7CiAgICBmb3IgKGludCBpID0gMDsgaSA8IDU7ICsraSkKICAgICAgICBmb3IgKGludCBqID0gaSArIDE7IGogPCA1OyArK2opCiAgICAgICAgICAgIGlmIChwW2ldLnRlbiA+IHBbal0udGVuKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB0ID0gcFtpXTsKICAgICAgICAgICAgICAgIHBbaV0gPSBwW2pdOwogICAgICAgICAgICAgICAgcFtqXSA9IHQ7CiAgICAgICAgICAgIH0KfQo=
compilation info
prog.c: In function ‘input’:
prog.c:24: error: ‘for’ loop initial declaration used outside C99 mode
prog.c:25: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result
prog.c: In function ‘output’:
prog.c:32: error: ‘for’ loop initial declaration used outside C99 mode
prog.c: In function ‘data_sort’:
prog.c:40: error: ‘for’ loop initial declaration used outside C99 mode
prog.c:41: error: ‘for’ loop initial declaration used outside C99 mode
stdout