分段错误,vfscanf.c:没有这样的文件或目录

时间:2019-05-30 11:35:21

标签: c

我正在尝试存储三角形,但似乎我的程序未读取它们。

   typedef struct{
      float x;
      float y;
    }point;
    typedef struct {
      point a;
      point b;
      point c;
    float area;
    }triangle;
    typedef struct{
      int numMax; // max
      int numTri; // current
      triangle *llista;
    }table;


    void iniciate(table t){

       t.llista=(triangle*)malloc((t.numMax)*sizeof(triangle));
     if(t.llista==NULL) exit(1);
     return;}


    void add(table t){

        if(t.numTri<t.numMax){
        printf("Dona un triangle\n");
        scanf("%f%f%f%f%f%f",&t.llista[t.numTri].a.x,&t.llista[t.numTri].a.y,&t.llista[t.numTri].b.x,&t.llista[t.numTri].b.y,&t.llista[t.numTri].c.x,&t.llista[t.numTri].c.y);
       t.numTri=t.numTri+1;
      }  
    return;}
     int main(void){

         table t;

       printf("Num max \n");
       scanf("%d",&t.numMax);
       tots.numTri=0;   
       iniciate(t);
       add(t); 
       return 0;}



 Program received signal SIGSEGV, Segmentation fault.
   0x00007ffff7a5377d in _IO_vfscanf_internal (s=<optimized out>, 
    format=<optimized out>, argptr=argptr@entry=0x7fffffffdd50, 
    errp=errp@entry=0x0) at vfscanf.c:2447
  2447  vfscanf.c: No such a file or directory

问题中可能重复的内容似乎无法解决我的问题。 错误是什么意思,我该如何解决?

0 个答案:

没有答案