#include <stdio.h>
#include <stdlib.h>
typedef struct _node {
int Coefficient;
int Exponent;
struct Node *next;
} Node;
typedef struct _list {
Node * head;
} List;
void insert(List * pList, int coeff, int expon);
void print(const List *pList);
int main()
{
List list1, list2, listSum, listProd;
list1.head = NULL;
list2.head = NULL;
listSum.head = NULL;
listProd.head = NULL;
int n, m;
int i;
int coeff, expon;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d %d", &coeff, &expon);
insert(&list1, coeff, expon);
}
scanf("%d", &m);
for (i = 0; i < m; i++) {
scanf("%d %d", &coeff, &expon);
insert(&list2, coeff, expon);
}
print(&list1);
print(&list2);
return 0;
}
void insert(List * pList, int coeff, int expon)
{
Node *p = (Node *)malloc(sizeof(Node));
p->Coefficient = coeff;
p->Exponent = expon;
p->next = NULL;
Node *last = pList->head;
if (last) {
while (last->next) {
last = last->next; //[Warning] assignment from incompatible pointer type
}
last->next = p; //[Warning] assignment from incompatible pointer type
}
else {
pList->head = p;
}
}
void print(const List *pList)
{
Node *p;
for (p = pList->head; p; p = p->next) { //[Warning] assignment from incompatible pointer type
printf("%d %d", p->Coefficient, p->Exponent);
if (p->next) {
printf(" ");
}
}
printf("\n");
}
dev gcc4.9.2 报warning,但是为什么报warning呢?
求大神指教:)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04)
变异只报warning:
test.c: In function ‘insert’:
test.c:49:18: warning: assignment from incompatible pointer type [enabled by default]
last = last->next; //[Warning] assignment from incompatible pointer type
^
test.c:51:20: warning: assignment from incompatible pointer type [enabled by default]
last->next = p; //[Warning] assignment from incompatible pointer type
^
test.c: In function ‘print’:
test.c:61:32: warning: assignment from incompatible pointer type [enabled by default]
for (p = pList->head; p; p = p->next) { //[Warning] assignment from incompatible pointer type
执行无错误
评论
全部评论 (0)