跪求C语言编程呐!题目如下,请看到的C语言程序高手帮帮我吧、明天就考试了,急需啊!!!!!!!!!

建立一个链表,每个节点包括:学生、姓名、性别、年龄。输入一个年龄,如果链表中的结点所包含的年龄等于此年龄,将此结点删去
不好意思哈、刚刚太着急输错问题了,我的问题是这样的:有十个学生,每个学生有学号,姓名,成绩,要求输入这十个学生的姓名、成绩建立动态列表,将这十个学生成绩输出到test.txt(要求每个学生信息占一行,每一项信息隔一个空格),
由于这是我的新号,悬赏分只有20分,都给你了,这题对我来说很重要,就麻烦你了哈

第1个回答  2011-06-30
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <assert.h>
#define N 10
#define MAX_SIZE 20

int main(void) {
typedef struct node {
int student_num;
int score;
char name[MAX_SIZE];
struct node* next;
} Node;

Node *root = NULL, *current = NULL, *next = NULL, *new_node = NULL;
int i, size=0;
FILE* fp;

current = root;
for (i = 0; i < N; ++i) {
new_node = (Node*)malloc(sizeof(Node));
assert(new_node != NULL);
new_node->next = NULL;

printf("请依次输入学号、分数和姓名:\n");
scanf("%d%d%s", &new_node->student_num, &new_node->score, new_node->name);

/* 在当前指向的节点后插入节点 */
if (current == root) {
root = new_node;
} else {
current->next = new_node;
}

/* 指向下一个 */
current = new_node;
}

/* 打开文件 */
fp = fopen("test.txt", "a");

if (fp == NULL) {
perror("test.txt");
return 1;
}

for (current = root; current != NULL; current = current->next) {
fprintf(fp, "%d %d %s\n", current->score, current->student_num, current->name);
}

fclose(fp);

for (current = root; current != NULL; current = next) {
next = current->next;
free(current);
}

system("echo 按任意test.txt&&pause>nul&&start test.txt");
return 0;
}
第2个回答  2011-06-30
typedef struct {
int no;
char name[20];
int sex;
int age;
}stuinfo;
typedef struct node{
stuinfo data;
struct node* next;
}Stunode *Stulist;
Stunlist RemoveByAge(int tage,Stulist thelist)
{
Stunode *p=thelist,*q=NULL;
q=p->next;
while(q!=null)
{
If(q->data.age==tage)
{
p->next=q->next;
free(q);
}
else
{
p=p->next
}
q=p->next;
}
return thelist;
}
生成链表时假设有头结点本回答被提问者采纳
第3个回答  2011-07-02
do
{
printf("%c",p->data);
}
while((p=p->next)!=NULL); /*遍历 链表*/
}
void main()
{
LINE *head;
Create(head);
printf("输入的文章为:");
OutPut(head);
printf("\n");
printf("全部字母数:%d \n",CountLetter(head));
printf("数字个数:%d \n",CountNumber(head));
printf("空格个数: %d \n",CountSpace(head));
printf("文章总字数: %d \n",CountAll(head));
char str1[20],str2[20];
printf("\n");
printf("请输入要统计的字符串:");
scanf("%s",str1);
printf("%s出现的次数为:%d \n",str1,FindString(head,str1));
printf("\n");
printf("请输入要删除的某一字符串:");
scanf("%s",str2);
DelString(head,str2);
printf("删除%s后的文章为:",str2);
OutPut(head);
}
相似回答