Ik wil een text file inlezen en deze naar een 2d array schrijven. Dit doe ik met de volgende code:
[code=C]#include <stdio.h>
#include <math.h>
#define KOLOM 6
#define RIJ 12
int main (void)
{
FILE *invoer;
int a=0, b=0;
int tabel[a][b];
invoer = fopen("test.txt", "r");
if(invoer != NULL)
{
printf("Bestand %s geopend\n", invoer);
for (a=0;a<RIJ;a++){
for (b=0;b<KOLOM;b++){
fscanf(invoer, "%d", &tabel[a][b]);
printf("%d\t", tabel[a][b]);
}
}
}
else{
printf("Bestand %s niet gevonden\n", invoer);
}
fclose(invoer);
return 0;
}
[/code=C]
De output is 10 kolommen en 8 rijen terwijl RIJ en KOLOM anders staan ingesteld. Ziet iemand wat ik hier fout doe?
[code=C]#include <stdio.h>
#include <math.h>
#define KOLOM 6
#define RIJ 12
int main (void)
{
FILE *invoer;
int a=0, b=0;
int tabel[a][b];
invoer = fopen("test.txt", "r");
if(invoer != NULL)
{
printf("Bestand %s geopend\n", invoer);
for (a=0;a<RIJ;a++){
for (b=0;b<KOLOM;b++){
fscanf(invoer, "%d", &tabel[a][b]);
printf("%d\t", tabel[a][b]);
}
}
}
else{
printf("Bestand %s niet gevonden\n", invoer);
}
fclose(invoer);
return 0;
}
[/code=C]
De output is 10 kolommen en 8 rijen terwijl RIJ en KOLOM anders staan ingesteld. Ziet iemand wat ik hier fout doe?