I'm doing a program in c, where I need to read a file, place it in an array and compare the vertical and horizontal symmetry about ASCII symbols.
The input file contains a figure created
on the basis of any ASCII characters.
For example, the first figure shown in this document:
* *
* * * *
* * * *
* * * * * * Vertical
+ + + + + + + +
+ + + + + + +
+ + + +
+ + + + + + +
+ + + + + + + + Horizontal
would be represented in this file follows:
The program will analyze the figure, detecting all possible
symmetries that sample, and generating an output file with
Detailed information on all the symmetries detected. The
information generated in each case is as follows.
Yo I have done the following:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "funcions.h"
int main(int argc, char** argv)
{
FILE *f1;
int **matriu;
int test=0;
int N;
int i=0;
int M;
char c;
if ((f1=fopen("ejemplo.c","r")) == NULL) // obre l'arxiu
{
printf("No s'ha trobat cap fitxer anomenat així");
}
else
{
int N;
int i;
int j;
fscanf(f1,"%d",&N);
fscanf(f1,"%d",&M);
matriu=(int**) malloc((N*M*sizeof(int*))); //reserva l'espai necessari per la matriu
for(i=0; i<N; i++)
{
for (j=0;j<M;j++)
matriu[i]=(int*) malloc((N*sizeof(int)));
}
fLectura(matriu,f1,N);
fEscriure(matriu,f1,N); //llegeix el fitxer i coloca els valors al lloc corresponent de la matriu
//Aqui haura de comparar les files i columnes, i la suma de asteriscos per veure si es reursiva
}
// En aquesta part obrin l'arxiu i creem la matriu.
void fLectura(int **matriu,FILE *f1,int N)
{
int a,b,z;
for (a=0; a<N; a++)
{
for (b=0; b<N; b++)
{
fscanf(f1,"%d",&z);
matriu[a][b]=z;
//printf("matriu[%d][%d]: %d \n", a,b,matriu[a][b]);
}
}
}
void fEscriure(int **matriu,FILE *f1, int N)
{
int a,b;
fprintf(f1 ,"%d ", N);
for (a=0; a<N; a++)
{
for (b=0; b<N; b++)
{
printf("matriu[%d][%d]: %d \n", a,b,matriu[a][b]);
fprintf(f1 ,"%d ", matriu[a][b]);
}
}
}