C语言程序,满足下面的所有要求。 [英] A program in C language which satisfies all the requirements which are written below.

查看:83
本文介绍了C语言程序,满足下面的所有要求。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个程序,它将从输入文件中读取一堆整数,对它们进行排序,并将排序后的结果打印到输出文件。



你必须阅读来自input.txt的输入,您必须将输出写入output.txt。输入将包含每行一个整数,并且当您达到EOF时,您应该停止阅读。输出也应该每行一个整数。



警告:不要在output.txt上打印任何其他内容。不要打印请输入数字等提示。输出不应包含排序整数以外的任何内容,每行一个。



如果您的输入是这样的:



3

4

7

1

5

输出应该是



1

3

4

5

7



您必须能够从当前目录中名为input.txt的文件中读取输入。您必须能够以完全如上所示的格式读取文件 - 不要假设文件或标准输入中将提供任何其他信息。您必须将输出写入当前目录中名为output.txt的文件。除了预期的答案之外,不要在output.txt中写入或打印任何其他内容。



对于C / C ++程序,不要使用像conio这样的非标准包含文件。 h并且不要使用像clrscr或getch这样的非标准函数。仅使用标准C.不要在stdout或输出文件(如果有的话)上打印任何额外内容。



我尝试过:



实际上,我对C语言中的文件处理知之甚少。我试了但是我输入了我想要的确切输出,所以请求帮助。

请帮我解决这个问题,我需要用C语言编写的程序。

解决方案

因为这显然是家庭作业我认为没有人是会给你完整的答案。相反,如果你发布具体问题,你做了什么,你做了什么,我相信你会得到这些特定问题的帮助。



请记住在完成作业的所有要点之后,你学习并且只有通过做和解决才能实现。如果其他人为你做了所有的想法,你就不会学到这些东西。



如果你只是想到它,我相信你会开始快速学习。 :)


引用:

好友这不是我的功课,我曾参加过在线比赛但在那次比赛之前他们会提出这样的问题

这样的问题可能就有了原因。他们想看看你是否有一些技能(或者如果你的技能足以参加比赛,则告诉你)。但它并不关心。 CodeProject不是代码编写服务。



引用:

刚刚可以'得到排序,怎么做,现在告诉我。

这是相当粗鲁的,不会增加得到答案的机会。



无论如何,要回到主题并让它有资格作为答案:



在您选择的搜索引擎中输入类似c sort algorithm的内容应该指向您到C标准库函数 qsort - C ++参考 [ ^ ](不要被链接中的C ++烦恼,它是关于C)。


你需要以后真正学习C和C ++,这些链接是非常好的讲座。



这里是关于C和C的参考书的链接C ++由语言的作者提供。注意,C是C ++的祖先,所以知道C对C ++总是有用。

C编程语言 - 维基百科,免费的百科全书 [ ^ ]

https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2。 pdf [ ^ ]

http://www.ime.usp。 br / ~pf / Kernighan-Ritchie / C-Programming-Ebook.pdf [ ^ ]



C ++编程语言 [ ^ ]


Write a program which will read a bunch of integers from an input file, sort them, and print the sorted result to an output file.

You must read the input from input.txt and you must write the output to output.txt. The input will contain one integer per line, and you're expected to stop reading when you reach EOF. The output should also have one integer per line.

Warning: Do not print anything else to output.txt. Do not print prompts like "Please enter a number." The output should not contain anything other than the sorted integers, one per line.

If your input is something like this:

3
4
7
1
5
The output should be

1
3
4
5
7

You must be able to read the input from a file called input.txt in the current directory. You must be able to read the file in a format exactly as shown above - do not assume that any other information will be provided in the file or on standard input. You must write your output to a file called output.txt in the current directory. Do not write or print anything else into output.txt other than the expected answer.

For C/C++ programs, do not use non-standard include files like conio.h and do not use non-standard functions like clrscr or getch. Use only standard C. Do not print anything extra to stdout or to the output file (if any).

What I have tried:

Actually, I don't know much more of File Handling in C. I tried it but I failed for the exact output which I want, so asking for help.
Please help me with this, and I need the program in C language.

解决方案

As this is obviously homework I think no one is going to give you full answer. Instead if you post specific questions, what you have done and in what you're stuck at I believe that you'll get help to those specific problems.

Remember that after all the point in the homework is that you learn and that can be achieved only by doing and solving. If someone else does all the thinking for you, you won't learn these things.

If you just put your mind into it I'm sure you start learning things quickly. :)


Quote:

Buddy this is not my homework, I had taken part in an online competition but before that competition they give such questions

There will be probably a reason for such questions. They want to see if you have some skills (or show you if your skills are sufficient for the competition). But it does not care. CodeProject is not a code writing service.

Quote:

Just now can't getting the sorting, how to do that, just tell me that now.

That is rather rude and will not increase the chance to get an answer.

Anyway, to be back on topic and let this qualify as an answer:

Entering something like "c sort algorithm" into a search engine of your choice should point you to the C standard library function qsort - C++ Reference[^] (don't be irritated by the C++ in the link, it is about C).


You need to really learn C and C++ later, These links are very good lecture.

Here is links to references books on C and C++ by the authors of the languages. Note than C is the ancestor of C++, so knowing C is always useful with C++.
The C Programming Language - Wikipedia, the free encyclopedia[^]
https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf[^]
http://www.ime.usp.br/~pf/Kernighan-Ritchie/C-Programming-Ebook.pdf[^]

C++ Programing Language[^]


这篇关于C语言程序,满足下面的所有要求。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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