#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
FILE *arquivoRead;
FILE *arquivoEscrita;
char ch;
int count=0;
int lin, col;
arquivoRead = fopen(argv[3], "r");
if(arquivoRead == NULL) {
fprintf(stderr, "Erro na abertura do arquivo\n");
}
if(argc < 1) {
fprintf(stderr, "Quantidade insuficiente de parâmetros\n");
}
if(strcmp(argv[1], "-d") == 0 ) {
}
arquivoEscrita = fopen("arquivoEscrita.txt", "w");
while( (ch=fgetc(arquivoRead) ) != EOF ){
fprintf(arquivoEscrita, "%c", ch);
fprintf(stdout, "%c", ch);
count++;
}
char matriz[count][count];
while( (ch=fgetc(arquivoRead) ) != EOF ){
for(lin=0; lin<count; lin++){
for(col=0; col<count; col++){
matriz[lin][col] = ch;
}
}
}
printf("\n\n");
for(lin=0; lin<count; lin++){
for(col=0; col<count; col++){
fprintf(stdout, "%c ", matriz[lin][col]);
}
printf("\n");
}
fclose(arquivoRead);
fclose(arquivoEscrita);
return 0;
}
I'm trying to put all these characters in an array of char, but I need to know the total of characters. The value of the counter gets either 0 or a strange value, moreover, the array is only storing garbage values from memory.