帮助newb的项目 [英] Help with newb's project

查看:63
本文介绍了帮助newb的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我是C编程新手并寻求帮助。我有一个家庭作业

项目要做

并且可以使用我可以得到的每个提示,建议,代码示例和参考。


这就是我需要做的事情。我有一个名为books.txt的文件,其中包含所有

信息

。每本书都是一个结构,包含在

文件夹中

分隔行上写的6个字段。我需要使用fgetc命令来读取这个文件的信息。


程序必须按照书的主题创建2个按字母排序的顺序和

对于一个

相同的主题,其他信息必须按照autor的名称分组。


第二个列表必须按照降序排列预订'

发布日期,

每年,信息必须按主题分组。


这些还必须在名为

booksort.txt的另一个文件中创建两个列表。每个autor'的
名字和姓氏必须是统一的(除了第一个

字符外全部小写)。此外,

如果名字只包含1个字符,则必须跟随''。''(即史密斯

Marc L.)。如果找到了

非字符('' - '','','',''。''等),我们必须将其替换为/

并添加

正确的空格数(即Marc * Smith现在是Marc / Smith)


最后,我们必须将日期的格式从当前文件(m / d / yyyy)更改

到(yyyy / mm / dd)

对我来说看起来很多工作所以我说,我正在收拾任何可以帮助我的东西。

感谢您的时间和帮助新手找到自己的方式!


弗兰克

Hi all,

I''m new to C programming and looking for some help. I have a homework
project to do
and could use every tips, advises, code sample and references I can get.

Here''s what I need to do. I have a file named books.txt that contains all
the informations
on the books. Each book is a struc containing 6 fields written on
separated line in the
folder. I need to use the fgetc command to read the info of this file.

The program must create 2 alphabetical order sorted by book''s subject and
for a
same subject, the other info must be grouped by autor''s name.

The second list must be created sorted in decreasing order of the book''s
release date, and
for each year, the info must be grouped by subject.

Nos these two lists must also be created in another file named
booksort.txt. Each autor''s
first and last name must be uniform (all lowercase except for the first
character). Also,
if a first name contains only 1 character, a ''.'' must follow (ie. Smith
Marc L.). If a
non-character is found (''-'', '','', ''.'', etc.), we must replace it by a "/"
and add the
correct number of spaces (ie. Marc*Smith is now Marc / Smith)

Finaly, we must change the date''s format from the current file (m/d/yyyy)
to (yyyy/mm/dd)
Looks like a lot of job to me so as I said, I''m tking anything that can
help me.
Thanks for your time and for helping a newb finding his way !

Frank

推荐答案

2004年10月23日星期六18:33:50 -0400

" The_Kingpin" <第********** @ hotmail.com>写道:

你好

我认为你拿一本好的C编程书并尝试自己做事会更好。我不认为你写这个程序会很困难。但是如果你想成为一名程序员,你必须自己学习如何找到解决方案;)当你要编写的程序是你作业的一部分时,这更加真实。


for一本手册我认为K& R并不是一个糟糕的选择(看看这个小组中有关于这个主题的一个主题)


BTW我不认为comp.lang。 c在这里做你的功课;)

i认为这个小组中的其他人会同意我的观点;)


尝试做练习(写一些算法和东西)如果有什么你不明白给我一个标志:)


弗拉基米尔


PS:我现在可以给你的唯一建议就是开始自己思考:-)和_understand_你正在编写的每行代码的目的是什么。

On Sat, 23 Oct 2004 18:33:50 -0400
"The_Kingpin" <th**********@hotmail.com> wrote:
hi there
i think it will be better for you to take a good C - programming book and try doing things by yourself. I don''t think it would be very difficult for you to write this program. But if you want to become a programmer you have to learn how to find solutions by yourself ;) This is enen more true when the program to write is a part of your homework.

for a manual i think K&R is not a bad choice (have a look there is a thread in this group about the subject)

BTW i don''t think comp.lang.c is here to do you your homework ;)
i think other people in this group will agree with my point of view ;)

try doing your exercise (write some algorithms and stuff) and if there is something you don''t understand give me a sign :)

Vladimir

PS: The only advice i can give you at the moment is to start thinking by yourself :-) and _understand_ what''s the purpose of each line of code you are writing.


我是C编程新手并寻求帮助。我有一个家庭作业
项目可以使用我可以得到的每个提示,建议,代码示例和参考。

这就是我需要做的。我有一个名为books.txt的文件,其中包含书籍上的所有信息
。每本书都是一个包含6个字段的结构,这些字段写在
分隔行的
文件夹中。我需要使用fgetc命令来读取该文件的信息。

该程序必须创建2个字母顺序,按书的主题排序,
为同一主题,其他信息必须按照autor的名称分组。

第二个列表必须按照书的发布日期的递减顺序创建,并且
对于每年,信息必须按主题分组。

这两个列表也必须在另一个名为
booksort.txt的文件中创建。每个autor'的名字和姓氏必须是统一的(除第一个
字符外全部小写)。此外,如果名字只包含1个字符,则必须跟随''。''(即史密斯
Marc L.)。如果找到了一个非字符(' - '','','',''。''等),我们必须用/和/或替换它。添加
正确数量的空格(即Marc * Smith现在是Marc / Smith)

最后,我们必须从当前文件更改日期的格式(m / d / yyyy)
to(yyyy / mm / dd)

对我来说看起来像很多工作,所以我说,我正在收拾任何可以帮助我的东西。
感谢您的时间和帮助新手找到自己的方式!

Frank
Hi all,

I''m new to C programming and looking for some help. I have a homework
project to do
and could use every tips, advises, code sample and references I can get.

Here''s what I need to do. I have a file named books.txt that contains all
the informations
on the books. Each book is a struc containing 6 fields written on
separated line in the
folder. I need to use the fgetc command to read the info of this file.

The program must create 2 alphabetical order sorted by book''s subject and
for a
same subject, the other info must be grouped by autor''s name.

The second list must be created sorted in decreasing order of the book''s
release date, and
for each year, the info must be grouped by subject.

Nos these two lists must also be created in another file named
booksort.txt. Each autor''s
first and last name must be uniform (all lowercase except for the first
character). Also,
if a first name contains only 1 character, a ''.'' must follow (ie. Smith
Marc L.). If a
non-character is found (''-'', '','', ''.'', etc.), we must replace it by a "/"
and add the
correct number of spaces (ie. Marc*Smith is now Marc / Smith)

Finaly, we must change the date''s format from the current file (m/d/yyyy)
to (yyyy/mm/dd)
Looks like a lot of job to me so as I said, I''m tking anything that can
help me.
Thanks for your time and for helping a newb finding his way !

Frank



-

Un * x很性感:

谁| grep -i blonde |日期; cd〜;解压缩;触摸;跳闸;手指;

mount;喘气;是;正常运行时间;卸除;睡觉


--
Un*x is Sexy:
who | grep -i blonde | date; cd ~; unzip; touch; strip; finger;
mount; gasp; yes; uptime; umount; sleep




" The_Kingpin" <第********** @ hotmail.com>写了

"The_Kingpin" <th**********@hotmail.com> wrote

我是C编程新手并寻求帮助。我有一个家庭作业
项目,可以使用我可以得到的每个提示,建议,代码示例和
参考。

这就是我需要做的。我有一个名为books.txt的文件,其中包含书籍上的所有信息。每本书都是一个包含6个字段的结构,分别写在文件夹中。我需要使用fgetc命令
来读取该文件的信息。

首先是一些术语。 结构是一个C构造,它在内存中对相关的数据进行分组。 记录是数据库中的条目。两个记录

和结构都有字段,但通常我们称之为结构字段。一个

的成员。


fgetc()一次读取一个字节的文件。您的导师

可能有理由要您使用此功能。通常情况下,人们会使用fgets()或

fscanf()来执行任务。

在内存中读取一行相对容易。更难的部分是解析

它。你的选项是scanf()函数系列,它们有一个你需要学习构造的格式

字符串,strtok(),它会将

字符串分解为你的标记,或使用strtol(),strcpy(),

strcmp()以及类似的函数来打破你自己的标记。

你需要注意数据文件有时会损坏,并拒绝任何错误的输入。


提取了六个字段后,您只需将它们分配给相关的

结构成员。所以如果你有标题,作者,价格,出版商,

出版年份,以及国会图书馆号码你可能有


结构书

{

char title [64];

char author [64];

char publisher [64];

双倍价格;

int year;

struct LibCongId congress_id;

};


struct LibCongId将包含用于包含图书馆的子字段

国会号码。

一个问题是你不知道有多少记录在直到

你已解析它。因此,您需要使用realloc()来扩展您的

书籍列表,这样您就可以阅读任何大小的文件。

该程序必须创建2个字母对于同一主题,按照书籍的主题和
排序,其他信息必须按照autor的名称分组。

第二个列表必须按照降序排列这本书的发布日期和每年的信息必须按主题分组。

所以你需要两次调用qsort(),一次使用第一个比较函数,

输出数据,然后输出第二个。
这两个列表也必须在另一个名为
booksort.txt的文件中创建。每个autor的名字和姓氏必须是统一的(除第一个字符外,所有
小写)。此外,如果名字只包含1
字符,则必须跟随''。''(即Smith Marc L.)。如果找到非字符('' - '',
'','',''。''等),我们必须将其替换为/。并添加正确的空格数
(即Marc * Smith现在是Marc / Smith)

这有点繁琐,也是错误的。爱尔兰和苏格兰的名字通常不会遵循这些规则。你需要一个函数formatname(char * out,const char

*输入)
最后,我们必须从当前文件(m / d / yyyy)改变日期的格式
到(yyyy / mm / dd)

这并不太难。在内部以您自己的格式存储所有日期,

然后按要求将它们打印出来。
对我来说看起来像很多工作,所以我说,我正在收拾任何可以<帮助我。
感谢您的时间和帮助新手找到自己的方式!

I''m new to C programming and looking for some help. I have a homework
project to do and could use every tips, advises, code sample and references I can get.

Here''s what I need to do. I have a file named books.txt that contains all
the informations on the books. Each book is a struc containing 6 fields
written on separated line in the folder. I need to use the fgetc command to read the info of this file.
First a bit of terminology. A "struct" is a C construct that groups related
pieces of data in memory. A "record" is an entry in a database. Both records
and structs have "fields", but normally we would call a struct "field" a
member.

fgetc() reads a file a byte at a time. There may be a reason your tutor
wants you to use this function. Normally however one would use fgets() or
fscanf() for the task.
Reading a line into memory is relatively easy. The harder part is parsing
it. Your options are the scanf() family of functions, which have a format
string you need to learn to construct, strtok(), which will break up the
string into tokens for you, or roll your own using strtol(), strcpy(),
strcmp() and suchlike functions to break the line up.
You need to be aware that data files are sometimes corrupt, and reject any
malformed input.

Having extracted the six fields, you simply assign them to the relevant
members of the structure. So if you have title, author, price, publisher,
year of publication, and Library of Congress number you might have

struct book
{
char title[64];
char author[64];
char publisher[64];
double price;
int year;
struct LibCongId congress_id;
};

struct LibCongId would contain the subfields used to contain a Library of
Congress number.
One problem is that you don''t know how many records are in the file until
you have parsed it. For this reason you need to use realloc() to expand your
list of books, so you can read in a file of any size.

The program must create 2 alphabetical order sorted by book''s subject and
for a same subject, the other info must be grouped by autor''s name.

The second list must be created sorted in decreasing order of the book''s
release date, and for each year, the info must be grouped by subject.
So you need to call qsort() twice, once with the first comparison function,
output the data, and then with the second.
Nos these two lists must also be created in another file named
booksort.txt. Each autor''s first and last name must be uniform (all lowercase except for the first character). Also, if a first name contains only 1 character, a ''.'' must follow (ie. Smith Marc L.). If a non-character is found (''-'', '','', ''.'', etc.), we must replace it by a "/" and add the correct number of spaces (ie. Marc*Smith is now Marc / Smith)
This is a bit fiddly, and also wrong. Irish and Scottish names often don''t
follow those rules. You need a function formatname(char *out, const char
*input)
Finaly, we must change the date''s format from the current file (m/d/yyyy)
to (yyyy/mm/dd)
That''s not too difficult. Store all dates internally in your own format,
then print them out as demanded.
Looks like a lot of job to me so as I said, I''m tking anything that can
help me.
Thanks for your time and for helping a newb finding his way !



如果您有任何实际问题,请发布您的代码。对于第一个
程序来说这是一个相当重要的任务。

首先定义你的记录结构,然后编写一个函数

来读取在一个,像这样


/ *

读取记录

成功时返回0,读取错误返回-1, - 2行太长(等)

* /

int readrecord(FILE * fp,struct book * out)


读取整个文件,在必要时调用realloc(),并编写一个

测试函数将其打印出来以确保其正常运行。

然后编写排序。

然后写出输出日期,然后输出你的记录。

最后写下名字格式代码,这可以留到最后。

如果你不能做到至少你会有90%的功能程序。


Post your code if you have any real problems. It is quite a task for a first
program.
Start by defining your structure for the records, and then write a function
to read in one, like this

/*
reads a record
returns 0 on success, -1 for read error, -2 for line too long (etc)
*/
int readrecord(FILE *fp, struct book *out)

The read in the whole file, calling realloc() where necessary, and write a
test function to print it out to ensure it runs properly.
Then write the sorts.
Then write the output date, and then output your records.
Finally write the name formatting code, which will can be left until last.
If you can''t do it at least you will have a 90% functional program.


The_Kingpin写道:
The_Kingpin wrote:

我是C编程新手,正在寻求帮助。我有一个
家庭作业项目,可以使用我可以得到的每个提示,建议,代码样本和参考。

这就是我需要做的。 ......剪辑...

I''m new to C programming and looking for some help. I have a
homework project to do and could use every tips, advises, code
sample and references I can get.

Here''s what I need to do. ... snip ...




这就是你需要做的事:听你的讲座,阅读你的
教科书,做一个合理的努力,然后寻求帮助,如果你自己没有发现足够的话。


要完成你的功课,你必须a)提供资金b)提供您的

教师的电子邮件地址以供提交,以及c)提供您的实际姓名和地址。金钱部分可能会被提前支付每小时100美元。


作为免费样品,这是一个有效的程序,你可以修饰:


#include< stdio.h>

int main(void){return EOF == puts(" Done");}


在i / o错误上有未定义行为的小错误。


-

Chuck F( cb********@yahoo.com)(cb********@worldnet.att.net)

可用于咨询/临时嵌入式和系统。

< http://cbfalconer.home.att.net>使用worldnet地址!



Here''s what you need to do: Listen to your lectures, read your
textbook, make a reasonable effort and then ask for help if you
haven''t discovered enough yourself.

To have your homework done you must a) offer money b) supply your
instructors e-mail address for the submission and c) supply your
own real name and address. The money part will probably be covered
by USD 100 per hour, in advance.

As a free sample, here is a valid program that you can embellish:

#include <stdio.h>
int main(void) {return EOF == puts("Done");}

It has the minor bug of undefined behaviour on an i/o error.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


这篇关于帮助newb的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆