#include #include #include #include #include #include #include #include struct t_aluno{ char nome[40]; long matricula; double media; char sexo; int ingresso; }; void gera_aluno( struct t_aluno *a) { int r; char sufixo[20]; r = rand(); sprintf( sufixo, "%d", r); strcpy( a->nome, "nome do aluno -->"); strcat( a->nome, sufixo ); a->matricula = r; a->media = 5.5; a->sexo = r%2==0?'M':'F'; a->ingresso = 2000; printf("Gerou aluno >>>%s<<<\n", a->nome); } int main( int argc, char *argv[]) { int n_regs; /* numero de registros a serem criados */ int fd; /* descritor do arquivo */ int i, w; long tam; /* tamanho do arquivo */ struct t_aluno aluno; /* buffer auxiliar */ int semente; /* semente para geracao de numeros aleatorios */ semente = (int) time(NULL) % 10000; srand(semente); printf("Semente aleatoria %ld\n", semente ); if( argc != 3 ) { printf("gerador nome-do-arquivo numero-de-registros\n"); exit(1); } n_regs = atoi( argv[2] ); if( n_regs < 1 || n_regs > 100000 ) { printf("Numero de registros deve estar entre 1 e 99999\n"); exit(1); } fd = open( argv[1], O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE); if( fd == -1 ) { printf("Nao conseguiu criar o arquivo %s\n", argv[1]); exit(1); } for( i=0; i