Recovering Matrix from a file.
Hello, so i've this program that scan and print the matrix from a file. anyways the program i have works with normal matrix i mean Square matrix but now i want to make a manual matrix i mean i've to enter the number of lines/columns and then i call the lines and columns in the main.
So the program below explains the situation
Code:
int recuperation (int t[][20], char *nomFichier){
int nbElement=0 ,i,j,nbElement2=0;
FILE *fp;
fp=fopen(nomFichier,"r");
if(fp!=NULL)
{
fscanf(fp,"%d\n",&nbElement);
fscanf(fp,"%d\n",&nbElement2);
if(nbElement && nbElement2)
{
for(i=1;i<=nbElement;i++)
{
for(j=1;j<=nbElement2;j++)
{
fscanf(fp,"%d",&t[i-1][j-1]);
}
}
}
}
else
printf("\n Fichier vide \n");
return nbElement;;
}
You see the return? nbElement that's the number of lines but i want to return the number of columns too, which is nbElement2.
Because later in main() i've to call this function by typing:
l= recuperation(t,txtfile)
but i can't call the columns since i returned only 1 value.
Hope that you got what i mean, thanks.