Program using pointers in C crashes. Unable to find the mistake
<p>I have written a program which accepts the number of students and the number of subjects. I need to accepts the marks in all subjects for each student and print each students total marks.
I have used pointers instead of an array since we do not know the number of students/subjects.
The function causing the problem might be this one:
n=students,m=subjects and sm is a pointer object of a structure which contains pointer 'marks'.</p>

<pre><code>#include&lt;stdio.h&gt;
#include&lt;math.h&gt;
#include&lt;stdlib.h&gt;

void accept(int,int); //Function Prototype
void calc(int,int);//Function Prototype
void print(int);//Function Prototype
struct student{
    float *marks;
}*sm;
float *total;
int main(){
    int n,m;
    printf("Enter number of students(N) and number of subjects(M) \n");
    scanf("%d%d",&amp;n,&amp;m);
    sm=malloc(n);
    sm-&gt;marks=malloc(m);
    total=malloc(n);
    accept(n,m);
    calc(n,m);
    print(n);
    return 0;
}
void accept(int n,int m){ //Accepts data
    int i,p;
    for(i=0;i&lt;n;i++){
    printf("Enter the marks of student %d in each subject in order and separated by a space/line \n",i+1);
    for(p=0;p&lt;m;p++){
        scanf("%f",(sm+i)-&gt;marks+p);
        }
    }
}
void calc(int n,int m){ //Calculates total marks
    int i,p,tot=0;
    for(i=0;i&lt;n;i++){
        for(p=0;p&lt;m;p++){
            tot+=*((sm+i)-&gt;marks+p);
        }
        *(total+i)=tot;
        tot=0;
    }
}
void print(int n){//Print the total marks of each student
    int i,tot=0;
    for(i=0;i&lt;n;i++){
        printf("Total marks for student %d is:%0.2f \n",i+1,*(total+i));
    }
}
</code></pre>

<p>The program crashes whenever the number of students>1 . I do not understand why and I have tried many ways to fix it but none have worked so far.
What is my mistake?</p>