我正在编写以下 c 代码并收到错误:
#include<stdio.h>
#include<stdlib.h>
int main()
{
char *prot;
char addr[20];
FILE *fp;
int i = 0;
int tos,pld;
prot = (char *)malloc(sizeof(char *));
//addr = (char *)malloc(sizeof(char *));
printf("\n enter the protocol for test::");
scanf(" %s",prot);
printf("\n enter the addr::");
scanf(" %s",addr);
printf("\n enter the length of the payload::");
scanf(" %d",pld);
printf("\n enter the tos :: ");
scanf(" %d",tos);
输入值时出现以下错误。出现分段错误,谁能告诉我为什么会出现此分段错误:
enter the protocol for test::we
enter the addr::qw
enter the length of the payload::12
Segmentation fault