第13行, list N1 = (list)malloc(sizeof(node)); 应修改为:list N1 = (list)malloc(sizeof(struct node));
第17行,list N = (list)malloc(sizeof(node)); 应修改为:list N = (list)malloc(sizeof(struct node));
后面两个是警告,提示 scanf()函数的返回值没有使用。修改见注释处,供参考:
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
typedef struct node* list;
struct node
{
int data;
list next;
};
list initN() {
int K = 0, r;
do{ //修改
r = scanf("%d", &K);
getchar();
}while(r != 1); //修改
list N1 = (list)malloc(sizeof(struct node));//修改
N1->data = 0;
N1->next = NULL;
for (; K > 0; K--) {
list N = (list)malloc(sizeof(struct node));//修改
int data = 0;
do{ //修改
r = scanf("%d", &data);
getchar();
}while(r != 1);//修改
N->data = data;
N->next = N1->next;
N1->next = N;
}
return N1;
}
int combine(list N) {
int record = 0;
int finding=0;
while (N->next != NULL) {
finding += N->next->data;
N = N->next;
if (finding <= 0) {
finding = 0;
}
if (finding > record) {
record = finding;
}
}
return record;
}
int main() {
list N1 = initN();
printf("%d", combine(N1));
return 0;
}