c语言malloc函数
如何同时使用两个malloc函数例如这里为啥不行呢!
#include <stdio.h>
#include <stdlib.h>
void ReadScore(long *pn,float *ps,int n,int m);
void PrintScore(long *pn,float *ps,int n,int m);
int main()
{
int n, m, choice;
long num[30];
float score[100];
long *ps = num;
float *pn = score;
printf("Please input the number of students:");
scanf("%d", &n);
printf("Please input the number of couses:");
scanf("%d", &m);
ps = (int*)malloc(n*sizeof(int));
pn = (float*)malloc(n*m, sizeof(float));
if(ps == NULL || pn == NULL)
{
exit(1);
}
ReadScore(pn,ps,n,m);
return 0;
}
void ReadScore(long *pn,float *ps,int n,int m)
{
int i;
for(i = 0; i<n; i++)
{
printf("Input num and score :");
scanf("%ld%f",&pn[i]);
for(j = 0; j < m; j++)
{
scanf("%f", &ps(i*n+j));
}
printf("\n");
}
}