警告:从malloc的不兼容指针类型赋值?

时间:2016-11-27 21:08:16

标签: c

我看了关于这个问题的另外两个问题,但我认为它们是不同的。谢谢你的帮助。问题出在第18行。

.image {
  height:100px;
  background-color:red; 
}
.item{
  transform:translateY(-50%);
}
.center {
  background-color:blue; 
  width:300px;
  margin:0 auto;

}

.Aligner {
  display: flex;
  flex-direction:column;
}


.Aligner-item--top {
   width:100%;
   background:red;
}

.following {

  width:100%;
  background-color:yellow;
  
}

1 个答案:

答案 0 :(得分:1)

代码中存在多个问题:

  • 您将malloc()的返回值转换为(x*),但将其存储到指向int的指针,而不是指向x的指针。你为什么这么做?如果正确配置了有用的警告,编译器将在此处诊断出潜在的错误。

  • scanf("%s", array[3].name1);将一个单词存储到name1成员的array成员中,该成员尚未定义。 array的大小为2,唯一有效的索引值为01。此代码调用未定义的行为。

  • %s scanf格式也会导致潜在的缓冲区溢出,因为scanf可以尝试存储超过29个字符加上空终止符的成员。您应该使用%29s

  • 您的功能的目的是什么?