为何这段代码在Windows下编译通不过?
这段代码是我在Linux系统下写的,在Linux平台下编译能通过,运行也正常。可是发给同学的时候同学却说编译没办法通过。该同学用的是vc 6.0我又发给了另外一个同学,他用的貌似是vs。
编译也没能通过,而且错误信息和刚刚那位同学还不一样。
这是我的代码:
程序代码:
#include <stdio.h> #include <stdlib.h> #define MEMBER_MALLOC (struct member*)malloc(sizeof(struct member)) struct member { int num; int password; struct member *next; }; struct member* input(int *count_ptr, int *M_ptr) { int i = 1; struct member *head = NULL, *tail = NULL; printf("请输入人数: "); scanf("%d", count_ptr); printf("请输入M: "); scanf("%d", M_ptr); printf("请依次输入密码"); //创建循环链表 for (; i <= *count_ptr; i++) { struct member *node = MEMBER_MALLOC; scanf("%d", &(node->password)); node->num = i; node->next = NULL; if (NULL == head) head = tail = node; else { tail->next = node; tail = node; } //如果是最后一个节点,则把它的Next指向头节点 if (i == *count_ptr) node->next = head; } return head; } void run(struct member* list, int *count_ptr, int *M_ptr) { int ct = 0; //计数器 //让last指向最后一个元素,让current指向第一个元素 struct member *current, *last; last = current = list; while (last->next != current) last = last->next; //开始删人 while (1 != (*count_ptr - ct)) { int flag; //找到要删除的人 for(flag = 1; flag != *M_ptr; flag++) { current = current->next; last = last->next; } //删人,从链表中移除,计数器加一 ct++; struct member* temp = current; current = current->next; last->next = current; printf("%d\n", temp->num); *M_ptr = temp->password; free(temp); } printf("%d\n", current->num); //删除最后一个人 free(current); } int main() { int count; //人数 int M; //M struct member *list = NULL; list = input(&count, &M); run(list, &count, &M); return 0; }
源代码也能在这里看到:
各位同学能不能帮我编译下
[ 本帖最后由 thlgood 于 2012-9-4 16:21 编辑 ]