Originariamente inviata da
wFree
Sì, ecco!
codice:
#define N 50
FILE* ff;
int righe=0;
char matrix [righe+1][N+1];
char str[N+2]={0};
int i=0, len=0;
ff=fopen("cruciverba.txt", "r");
codice:
char matrix [righe+1][N+1];
questa riga è sbagliata!
In ogni caso è più semplice usare una memset e una strncpy
codice:
#include <stdio.h>
#include <string.h>
#define N 50
int main()
{
FILE *fp;
char buff[N];
char mat[N][N];
memset(mat, '.', N*N);
int righe;
fp = fopen("input.txt", "r");
if( fp != NULL ){
righe = 0;
while ( fgets(buff, N, fp) != NULL ){
if(buff[strlen(buff)-1] == '\n') buff[strlen(buff)-1] = '\0';
strncpy(mat[righe], buff, strlen(buff));
++righe;
}
fclose(fp);
}
return 0;
}