C实训题目一道~求找错
题目五 信息发布平台1. 设计要求:
基本功能:
a) 查看信息
b) 查看评论
c) 发布信息
d) 发表评论
e) 删除信息
f) 删除评论
拓展功能:
采用文件形式对信息和评论数据进行操作,包括:
a) 写入文件
b) 读取文件
创新(自拟)功能:
程序实现的其它功能由个人自拟。
2. 设计要求具体说明
基本功能:
信息记录中包含以下数据:
信息编号、发布者姓名、信息时间、信息内容
评论记录中包含以下数据:
评论编号、评论者姓名、评论时间、评论内容、被评论信息编号
查看信息
列表显示当前所有信息数据
查看评论
要求输入一个信息编号(要求对信息编号进行检查,如果没有这条信息,显示输入编号错误),查看对该信息的所有评论内容
发布信息
要求输入信息编号、发布者姓名、信息时间、信息内容。要求信息编号不能重复。
发表评论
要求先输入一个信息编号(要求对信息编号进行检查,如果没有这条信息,显示输入编号错误),然后输入评论编号、评论者姓名、评论时间、评论内容. 要求评论编号不能重复。
删除信息
输入一个信息编号,先查询是否存在该信息,如果存在删除该信息记录,如果不存在显
8
程序设计语言课程设计指导书
示无记录。
删除评论
输入一个评论编号,先查询是否存在该评论,如果存在删除该评论记录,如果不存在显示无记录。
拓展功能
要求对上述输入的信息和评论记录进行文件保存,下次进入系统时从文件读出数据。
程序:
#include <stdio.h>
#include <stdlib.h>
struct message
{
int number;
char name[20];
char date[20];
char content[10000];
}a[100] = {-1};
struct comment
{
int number;
char name[20];
char date[20];
char content[10000];
}b[100][100] = {-1};
//void initialize(struct message a[100], struct comment b[100][100]);
void main_interface(void);
void search_message(struct message a[100]);
void search_comment(struct comment b[100][100]);
void issue_message(struct message a[]);
void issue_comment(struct comment b[100][100]);
void delete_message(struct message a[100]);
void delete_comment(struct message a[100], struct comment b[100][100]);
int main()
{
int com;
while(1)
{
initialize(a, b);
main_interface();
printf("êäèëÖ¸áî: ");
scanf("%d", &com);
switch (com)
{
case 1 : search_message(a); break;
case 2 : search_comment(b); break;
case 3 : issue_message (a); break;
case 4 : issue_comment (b); break;
case 5 : delete_message(a); break;
// case 6 : read a file (); break;
// case 7 : write a file (); break;
case 8 : exit(0);
case 0 : delete_comment(a, b); break;
default: printf("illegal\n");
}
}
return 0;
}
/*void initialize(struct message a[100], struct comment b[100][100])
{
int z, w;
for(z = 0; z < 100; z++)
{
a[z].number = -1;
for(w = 0; w < 100; w++)
{
b[z][w].number = -1;
}
}
}*/
void main_interface(void)
{
printf("DÅÏ¢·¢2¼Æ½ì¨\n\n");
printf("1. 2é¿′DÅÏ¢\n");
printf("2. 2é¿′ÆàÂÛ\n");
printf("3. ·¢2¼DÅÏ¢\n");
printf("4. ·¢±íÆàÂÛ\n");
printf("5. é¾3yDÅÏ¢\n");
printf("6. ¶áèëÎļt\n");
printf("7. D′èëÎļt\n");
printf("8. íË3ö3ìDò\n");
printf("0. é¾3yÆàÂÛ\n");
}
void search_message(struct message a[100])
{
int i;
for(i = 0; i < 100; i++)
{
if(a[i].number >= 0)
{
printf("%d\t%s\t%s\n", a[i].number, a[i].name, a[i].date);
printf("content: \n\t%s\n", a[i].content);
}
}
}
void search_comment(struct comment b[100][100])
{
int temper, j, t;
while(1)
{
printf("Inter the number of the message: ");
scanf("%d", &temper);
if(temper < 0)
{
printf("the message don't exit.\n");
return;
}
else
{
for(j = 0, t = 0; j < 100; j++)
{
if(b[temper][j].number >= 0)
{
printf("%d\t%s\t%s\t\n", b[temper][j].number, b[temper][j].name, b[temper][j].date);
printf("comment: \n\t%s\n", b[temper][j].content);
t++;
}
}
printf("The message has &d comment.\n", t);
}
}
}
void issue_message(struct message a[])
{
int tmp;
char ch;
while(1)
{
printf("Input your message's number: ");
scanf("%d", &tmp);
¡¡ if(a[tmp].number < 0) //134: error: stray '\161' in program
{
a[tmp].number = tmp;
break;
}
else
{
printf("Error\n");
printf("Continue or return to the interface.(c/r)\n");
ch = getche();
if(ch == 'r' || ch =='R')
{
return;
}
}
}
printf("Input your name: ");
scanf("%s", &a[tmp].name);
printf("Input the issue date: ");
scanf("%s", &a[tmp].date);
printf("Enter your message: \n");
scanf("%s", &a[tmp].content);
}
void issue_comment(struct comment b[100][100])
{
int tem1, tem2;
char ch;
while(1)
{
printf("Input the message's number that you want: ");
scanf("%d", &tem1);
if(a[tem1].number >= 0)
{
break;
}
else
{
printf("The message don't exit.\n");
}
}
while(1)
{
printf("Input you comment's number: ");
scanf("%d", tem2);
if(b[tem1][tem2].number < 0)
{
b[tem1][tem2].number = tem2;
break;
}
else
{
printf("Error\n");
printf("Continue or return to the interface.(c/r)\n");
ch = getche();
if(ch == 'r' || ch =='R')
{
return;
}
}
}
printf("Inter your name: ");
scanf("%s", &b[tem1][tem2].name);
printf("Inter the date: ");
scanf("%s", &b[tem1][tem2].date);
printf("Enter you comment: \n");
scanf("%s", &b[tem1][tem2].content);
}
void delete_message(struct message a[100])
{
int k;
printf("Inter the number you want to delete: ");
scanf("%d", &k);
if(a[k].number < 0)
{
printf("Error\nthe message don't exit.\n");
}
else
{
a[k].number = -1;
a[k].name ={'\0'};
a[k].date ={'\0'};
a[k].content={'\0'};
}
}
void delete_comment(struct message a[100], struct comment b[100][100])
{
int t1, t2;
printf("Enter the message' number: ");
scanf("%d", &t1);
if(a[t1].number < 0)
{
printf("The message don't exit.\n");
}
else
{
printf("Enter the comment's number: ");
scanf("%d", &t2);
if(b[t1][t2].number < 0)
{
printf("The comment don't exit.\n")
}
else
{
b[t1][t2].name = {'\0'};
b[t1][t2].date = {'\0'};
b[t1][t2].content = {'\0'};
}
}
}
编译器报错:
--------------------ÅäÖÃ: mingw5 - CUI Debug, ±àòëÆ÷ààDí: MinGW--------------------
¼ì2éÎļtòààμDÔ...
ÕyÔú±àòë C:\Users\Fay\Desktop\Access\ѧéú×êáÏ\program_5.c...
[Error] C:\Users\Fay\Desktop\Access\ѧéú×êáÏ\program_5.c:134: error: stray '\161' in program
[Error] C:\Users\Fay\Desktop\Access\ѧéú×êáÏ\program_5.c:134: error: stray '\161' in program
[Error] C:\Users\Fay\Desktop\Access\ѧéú×êáÏ\program_5.c:215: error: syntax error before '{' token
[Error] C:\Users\Fay\Desktop\Access\ѧéú×êáÏ\program_5.c:216: error: syntax error before '{' token
[Error] C:\Users\Fay\Desktop\Access\ѧéú×êáÏ\program_5.c:217: error: `k' undeclared here (not in a function)
[Error] C:\Users\Fay\Desktop\Access\ѧéú×êáÏ\program_5.c:217: error: syntax error before '.' token
[Error] C:\Users\Fay\Desktop\Access\ѧéú×êáÏ\program_5.c:237: error: syntax error before '}' token
[Error] C:\Users\Fay\Desktop\Access\ѧéú×êáÏ\program_5.c:240: error: syntax error before '{' token
[Error] C:\Users\Fay\Desktop\Access\ѧéú×êáÏ\program_5.c:241: error: syntax error before '{' token
[Error] C:\Users\Fay\Desktop\Access\ѧéú×êáÏ\program_5.c:242: error: syntax error before '{' token
11½¨ÖDÖ1 program_5: 10 ¸ö′íÎó, 0 ¸ö¾ˉ¸æ
PS:乱码部分是中文提示