12
返回列表 发新帖
楼主: 沧海ふ无涯
收起左侧

[软件] C语言基础 ACM 题 2则

[复制链接]
yege0201
发表于 2013-1-9 11:45:24 | 显示全部楼层
本帖最后由 yege0201 于 2013-1-9 11:46 编辑
沧海ふ无涯 发表于 2013-1-9 11:37
我们学的是   ansi C  和vc还是有差别的

整个ACM网站运行于ubuntu上,GCC编译。。。。


哎~微软总喜欢这样~用VC编写的程序代码到GCC上还要经过调试~冏啊~

我刚才吧我说的地方改了一下~用C-Free调试了~没有报错~完美运行~

不过有个[Warning] C:\Users\Driving_Myself\Documents\C-Free\Temp\未命名1.cpp:37:2: warning: no newline at end of file

我很汗啊~这个也能算warning吗~代码文件最后必须有一行空行~
沧海ふ无涯
 楼主| 发表于 2013-1-9 11:49:59 | 显示全部楼层
yege0201 发表于 2013-1-9 11:45
哎~微软总喜欢这样~用VC编写的程序代码到GCC上还要经过调试~冏啊~

我刚才吧我说的地方改了一下~用C- ...

这个是历史问题,以前查阅相关文档。。。。结果全是原文,貌似很深奥的样子。

用google搜索了一下,翻了几篇帖子,很快就找到了答案:
http://www.linuxquestions.org/questions/showthread.php?t=281830
"It's not an extra new-line, each line should be terminated by an "end of line" tag, and this is /n under unix.
On MacOS, this used to be /r, perhaps the reason why gcc is more tolerant on newer releases of this O/S."
-- 有人思考过 --
"do you know real reason of that?"
-- 马上就有人提出质疑 --
"There's probably still some ancient compilers out there (maybe even very old versions of GCC?) that want each line to end with a newline or else they crash. My guess is that GCC is just trying to help you make your code compatible with these dino's."
-- 接着就有人提出自己的观点 --
"Actually, gcc warns about it because it has to according to the standard. Check out this link for a brief description: http://gcc.gnu.org/ml/gcc/2003-11/msg01568.html
If you have a compiler that doesn't warn you about the lack of a newline character then that compiler doesn't meet the standards. Burn the disc it came on and get a real compiler."
-- 很快,依靠大家的力量,借助网络,答案浮出水面 --
"The C language standard says
A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character.

Since this is a "shall" clause, we must emit a diagnostic message for a violation of this rule.
This is in section 2.1.1.2 of the ANSI C 1989 standard. Section 5.1.1.2 of the ISO C 1999 standard (and probably also the ISO C 1990 standard)."
-- 原来是C语言的标准定义的 --
如果你有足够的怀疑精神,还可以继续寻求问题的本源——ISO C 1999 standard。
对此或许你有不同的想法,我希望你也可以拿出来讨论,不断交流,多方思维冲撞,才能快速进步。

评分

参与人数 1经验 +4 收起 理由
yloko + 4 感谢提供分享

查看全部评分

yege0201
发表于 2013-1-9 11:52:20 | 显示全部楼层
沧海ふ无涯 发表于 2013-1-9 11:49
这个是历史问题,以前查阅相关文档。。。。结果全是原文,貌似很深奥的样子。

历史遗留问题也不是咱能解决的~
数据流谷雨
发表于 2013-1-9 13:41:33 | 显示全部楼层
沧海ふ无涯 发表于 2013-1-9 11:34
首先,不管怎么样,对你还是表示感谢的,这么晚还帮我调试代码。。。

不过。。。。可能我复制 ...

我编的是题目2,不是题目1
题目描述现有有N个学生的数据记录,每个记录包括学号、姓名、三科成绩。编写一个函数input,用来输入一个学生的数据记录。编写一个函数print。。。
其实yege0201的方法也挺好的,他用全局变量,所以在函数中可以访问。而我在main函数中设置变量,不能再input、print函数中访问,要想访问需要用到指针,而我指针学的又不好,编出来的有问题
li13911
发表于 2013-1-9 14:17:55 | 显示全部楼层
数据流谷雨 发表于 2013-1-9 01:45
我调了一晚上,第二题还有问题,表现为第一次输入的姓名、学号显示成为第二次输入的姓名、学号,其他没问题

高人啊,直接指针操作。当时学习的时候除了题目要求,从来不敢乱用指针,当然自己用不好。
您需要登录后才可以回帖 登录 | 快速注册

本版积分规则

手机版|杀毒软件|软件论坛| 卡饭论坛

Copyright © KaFan  KaFan.cn All Rights Reserved.

Powered by Discuz! X3.4( 沪ICP备2020031077号-2 ) GMT+8, 2025-5-15 21:39 , Processed in 0.097746 second(s), 15 queries .

卡饭网所发布的一切软件、样本、工具、文章等仅限用于学习和研究,不得将上述内容用于商业或者其他非法用途,否则产生的一切后果自负,本站信息来自网络,版权争议问题与本站无关,您必须在下载后的24小时之内从您的电脑中彻底删除上述信息,如有问题请通过邮件与我们联系。

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