Lots to think about here
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.c>
int compara(char* a, char* b);
int main(){
char ENTRADA[50], SAIDA1[50], SAIDA2[50], NOMES[512][80];
FILE *LER;
FILE *ESCREVER2;
FILE *ESCREVER1;
int CONTADOR=0, AUX;
puts("informe o nome do arquivo de entrada sem extensao(ex. arquivo)");
//!! read
//!! http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1049157810&id=1043284351
gets(ENTRADA);
puts("informe o nome do arquivo de saida sem extensao(ex. arquivo)");
gets(SAIDA1);
strcat(ENTRADA, ".bin");
strcpy(SAIDA2,SAIDA1);
strcat(SAIDA1, "a-n.bin");
strcat(SAIDA2, "p-z.bin");
/*!! there are some () over-use issues here */
if ( ( ((LER = fopen(ENTRADA,"rb")) == NULL)||
((ESCREVER1 = fopen(SAIDA1,"wb")) == NULL)
) ||
((ESCREVER2 = fopen(SAIDA2,"wb")) == NULL)
) {
puts("Arquivo nao pode ser aberto.");
}
else{
do{
/*!! you don't check the return result of read */
fread(NOMES[CONTADOR+1], sizeof(NOMES[CONTADOR]), 1, LER);
/*!! strcat is bad here, fread() does NOT guarantee a \0 at the end */
/*!! of whatever data you've read in */
/*!! In addition, you've already filled the buffer with the read */
/*!! there is no room to append more data */
strcat(NOMES[CONTADOR], " sequencial: ");
/*!! my guess is you need to figure out sprintf to convert */
/*!! an int into a string, then append that string to your result */
strcat(NOMES[CONTADOR], CONTADOR);
/*!! Also, you DON'T increment your CONTADOR variable */
}while(!(feof(LER)));
//!! read
//!! http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046476070&id=1043284351
fclose(LER);
// veja mais dessa função em:
// http://www.phim.unibe.ch/comp_doc/c_manual/C/FUNCTIONS/qsort.html
// (biblioteca STDLIB.H)
qsort(NOMES, CONTADOR, 80, compara);
/*!! I'm sure the , should be a ; */
/*!! in addition, if you just want the data read, then */
/*!! the test should be <, not <= */
for(AUX=0;AUX<=CONTADOR, AUX++){
/*!! there are some () issues here */
/*!! In particular, there is a ) missing */
if ( ((NOMES[AUX][0]>='A')&&(NOMES[AUX][0]<='N')) ||
((NOMES[AUX][0]>='a')&&(NOMES[AUX][0]<='n')) {
fwrite(NOMES[AUX], 80, 1, SAIDA1);
}
else{
fwrite(NOMES[AUX], 80, 1, SAIDA2);
}
}
}
}
/*!! qsort compare functions are passed const void* pointers */
/*!! these you must cast to the appropriate type before comparing */
int compara(char *a, char *b)
{
return(strcmp(a, b));
}