problem whith c++ program matrix

My difficulty is that each matrix should have an identifier and match the same name where the file will be saved, so when i go to search for a file and write data, be easier, for example.




#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>



int main(){

/* Variable declaration */
FILE *fp;
int M[1][2],a,j,count=0,x=0,k,n[1][2];
fp=fopen("D:\\dados.txt","w");
if((fp==NULL)){
printf("Impossivel abrir o ficheiro.");
return(-1); }

/* Main code */

printf("\n");
for(a=0;a<1;a++)//for para escrever a matriz (linhas)
{
for(j=0;j<2;j++) //for para escrever a matriz (Colunas)
{
printf("Introduza o dado para M[%d][%d]:",a,j);

scanf("%d",&M[a][j]);
fprintf(fp,"%d\n",M[a][j]);

}
fclose(fp);
}
/*Aqui imprimo os numeros da matrize*/
fp=fopen("D:\\dados.txt","r");
for(a=0;a<1;a++)
{
for(j=0;j<2;j++)
{


fscanf(fp, "%d\n",&n[a][j]);

printf("%d\n",n[a][j]);




}
}
printf("\n");

fclose(fp);


}
Topic archived. No new replies allowed.