我试图让我的程序使用指针和 malloc 将 Scanf 的结果存储到内存中,我希望 Scanf 只能接受整数,这是我的代码。当我打印结果时,它会返回一个随机数?
int main(void)
{
unsigned int *Source = malloc(10);
printf("Enter a Source Number: ");
scanf("%i",Source);
printf("%i\n",Source);
unsigned int *Destination = malloc(4);
printf("Enter a Destination Number: ");
scanf("%i",Destination);
printf("%i\n",Destination);
unsigned int *Type = malloc(4);
printf("Enter a Type Number: ");
scanf("%i",Type);
printf("%i\n",Type);
int *Port = malloc(4);
printf("Enter a Port Number: ");
scanf("%i",Port);
printf("%i\n",Port);
char *Data;
struct Packet *next;
return 0;
}
任何人都可以解释一下吗?