#include #include #define N_MAX 10 struct elemento{ char c; int rig; int col; }; typedef struct elemento Elemento; void readfile(Elemento*, int *, FILE *); void struct2mat(Elemento*, int ,char [][N_MAX], int*,int*); void mat2vet(char [][N_MAX], int ,int, char *); int main() { Elemento v[N_MAX*N_MAX]; char mat[N_MAX][N_MAX]; char s[N_MAX*N_MAX]; int n, rig,col; FILE * fp; fp = fopen("input.txt","r"); if(fp==NULL) { printf("File input error"); } else{ readfile(v,&n,fp); fclose(fp); struct2mat(v,n,mat,&rig,&col); mat2vet(mat,rig,col,s); printf("%s\n",s); fp=fopen("output.bin","w"); if(fp!=NULL) { fwrite(v,sizeof(Elemento),N_MAX,fp); fclose(fp); } } } void readfile(Elemento*v, int *n, FILE *fp){ char line[100]; int go=1; char temp; *n=0; while(!feof(fp)&& go) { fgets(line,100,fp); line[strlen(line)-1]='\0'; go = strcmp(line,"stop")!=0; if (go) { temp=line[0]; fgets(line,100,fp); int i=0; while(i<(strlen(line)-1)) { v[*n].c=temp; v[*n].rig=line[i]-'0'; //v[*n].rig=line[i+2]-'0'; v[*n].col=line[i+2]-'0'; i+=4; *n+=1; } } } } void struct2mat(Elemento*v, int n,char m[][N_MAX], int *r,int *c){ *r=0; *c=0; for(int i=0;i