QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1014|回复: 4

请大家帮忙调试 : 运行

[复制链接]
发表于 2002-11-25 22:44:35 | 显示全部楼层 |阅读模式
[code:1]
#include<stdlib.h>
#include<sys/types.h>
#include<unistd.h>
#include<stdio.h>

struct proc{
char name[2];
int num;
struct proc *next;
};

int n;
struct proc *head, *this, *new, *current, *temp;

void new_record(void);
void sortlist(void);
void excutable(void);

pid_t pid;

main ()
{
int i, j;
for(i=0; i<=8; i++){
new_record();
}
sortlist();
excutable();
for(j=1; j<=7; j++){
current = head;
excutable();
if(n>2){
do{
this->num = this->num+1;
if(this->num > 32){
this->num = this->num%32;
sortlist();
}
this = this->next;
}while(this->next = NULL);
}
free(new);
}
} //lost a '}'


void new_record(void)
{
int i;
new = (struct proc *)malloc(sizeof (struct proc));
if(head == NULL)
head = new;
else{
this = head;
while(this->next!=NULL)
this = this->next;
this->next = new;
}
this = new;
printf("\nenter name:"); //what did u mean of '\e'??
scanf("%s",this->name);
printf("\nenter num:"); //what did u mean of '\e'??
this->num = i;
printf("\n new over");
this->next = NULL;
}

void sortlist(void)
{
int i,j;
this = head;
for(i=1; i<=8; i++)
for(j=i+1; j<=8; j++){
if(this->num < this->next->num){
temp = this;
this = this->next;
this->next = temp;
}
this = this->next;
}
}

void excutable(void)
{
n = random()%4;
current = head;
pid=fork();
if ( pid>0 ){
sleep(n);
}
}

[/code:1]
发表于 2002-11-25 22:59:43 | 显示全部楼层
以后大家贴出大段代码的时候记得用code的格式贴出来,这样方便别人阅读。
回复

使用道具 举报

发表于 2002-11-26 08:35:49 | 显示全部楼层
编译通过,运行错误!!
segmentation fault!
回复

使用道具 举报

发表于 2002-11-26 12:32:25 | 显示全部楼层
先讲讲是做什么的,要不好长,瞧得头痛!
回复

使用道具 举报

发表于 2002-11-26 12:48:28 | 显示全部楼层
好像是链表的操作,先输入链表内容,然后排序。效率不是很高
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-16 18:37 , Processed in 0.070830 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表