Да вы не поняли надо чтобы память выделялась без явного указания размера
| Код |
#include <iostream.h> #include <conio.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
#define dataEr printf("\t\t\t\t!!!ERROR!!! \n\n\t\tFILE IS EMPTY or no match symbolyc //|-> information!\n\n") #define FileEr printf("\t\t\t\t!!!ERROR!!! \n\n\t\tNo such fiLe or DirEctOry\n\n") #define QUIT printf("\nDo you want to close this program?(y/n)\t"); if( getche()=='y' ) exit(0)
struct socker { char name[40]; /*Вот тута и надо чтобы он был переменным*/ int wins; int fails; int nono; int out; int in; };
void printstruct(socker *pointer,int i);
int main() { int i,n; socker *p; FILE*f;
while(1) { printf("\nHow much team's information consist the file?\n"); scanf("%d",&n); p=new socker[n]; if ((f=fopen("C:\\in1.txt","r"))!=NULL) { for (i=0;i<n;i++) { // system("cls"); if(fscanf(f,"%s",&(p+sizeof(socker)*i)->name)==EOF) /* т.е тут надо выделять память динамически, ведь мы не знаем скоко символов в строке названия команды*/ { dataEr; break; } if(fscanf(f,"%d",&(p+sizeof(socker)*i)->wins)==EOF) { dataEr; break; } if(fscanf(f,"%d",&(p+sizeof(socker)*i)->fails)==EOF) { dataEr; break; } if(fscanf(f,"%d",&(p+sizeof(socker)*i)->nono)==EOF) { dataEr; break; } if(fscanf(f,"%d",&(p+sizeof(socker)*i)->out)==EOF) { dataEr; break; } if(fscanf(f,"%d",&(p+sizeof(socker)*i)->in)==EOF) { dataEr; break; } printstruct(p,i); getch(); } } else { FileEr; exit(0); } system("cls"); sort(p,n); for(i=0;i<n;i++) { printstruct(p,i); getch(); } fclose(f); delete p; QUIT; }
return 0; }
void printstruct(socker *p,int i) { //system("cls"); printf("\t\t\t\t|Team #%d|\n",i+1); printf("| Name | %s \n",*(p+sizeof(socker)*i)->name); printf("| Wins | %d \n",(p+sizeof(socker)*i)->wins); printf("| Fails | %d \n",(p+sizeof(socker)*i)->fails); printf("| Nono | %d \n",(p+sizeof(socker)*i)->nono); printf("| Out | %d \n",(p+sizeof(socker)*i)->out); printf("| In | %d \n",(p+sizeof(socker)*i)->in); }
|
во как |