摘要: 当前目录仅有四个文件:test.exetemptemp.atemp.txttemp.z此时,使用fopen("temp.", "r")打开的文件为temp。代码:#include #include int main(int argc, char* argv[]){ FILE *fp; i... 阅读全文
posted @ 2014-08-15 09:26 liuxia_hust 阅读(1777) 评论(0) 推荐(0) 编辑
摘要: 遇到一个问题,命令行参数复制到字符串后打印出来的结果与直接打印命令行参数的结果不一致。不清楚是哪里的问题。#include #include #define LEN 5int main(int argc, char* argv[]){ char s1[LEN]; char s2[LEN]... 阅读全文
posted @ 2014-08-14 21:08 liuxia_hust 阅读(275) 评论(0) 推荐(0) 编辑
摘要: 为了避免缓冲区溢出,从终端读取输入时应当用fgets()代替gets()函数。但是这也将带来一个问题,因为fgets()的调用格式是:fgets (buf, MAX, fp)fgets (buf, MAX, stdin)buf是一个char数组的名称,MAX是字符串的最大长度,fp是FILE指针。f... 阅读全文
posted @ 2014-08-14 20:35 liuxia_hust 阅读(46319) 评论(2) 推荐(0) 编辑
摘要: 新建Qt控制台应用。main.cpp:#include #include #include #include int main(int argc, char *argv[]){ QVector aVector; int N = 4096; for (int i = 0; i < N... 阅读全文
posted @ 2014-07-06 16:57 liuxia_hust 阅读(1989) 评论(0) 推荐(0) 编辑
摘要: C中的标准输入输出可以进行重定向到文件。示例程序:(C Primer Plus示例8.2)// echo_eof.c -- 重复输入,直到文件的结尾#include int main(void){ int ch; while ( (ch = getchar()) != EOF) ... 阅读全文
posted @ 2014-06-30 14:17 liuxia_hust 阅读(553) 评论(0) 推荐(0) 编辑
摘要: 程序清单6.5 compflt.c是比较浮点数是否相等的例子。原程序如下:// cmpflt.c -- 浮点数比较#include #include int main(void){ const double ANSWER = 3.14159; double response; printf("Wha... 阅读全文
posted @ 2014-06-24 16:34 liuxia_hust 阅读(260) 评论(0) 推荐(0) 编辑
摘要: 第五章的最后一个练习题,5-8.要求:/*输入一个华氏温度。以double类型读入温度值,并将它作为一个参数传递给用户提供的函数Temperatures()。该函数将计算对应的摄氏温度和绝对温度,并以小数点右边有两位数字的精度显示这三种温度。它应该用每个值所代表的温度刻度来标识这三个值。Celsiu... 阅读全文
posted @ 2014-06-24 15:40 liuxia_hust 阅读(334) 评论(0) 推荐(0) 编辑
摘要: 按照C Primer Plus中文第五版中的描述,long double 在使用scanf()函数读取时,应采用“%Lf" "%Le" "%Lg"作为控制字符串.如下代码分别在VC 2010 Express 、MinGW(gcc version 4.8.1 (tdm-2))和QT5.2.1 for ... 阅读全文
posted @ 2014-06-21 09:51 liuxia_hust 阅读(1252) 评论(0) 推荐(0) 编辑
摘要: 1显示程序执行的窗口一闪即逝。可以添加如下语句:getchar()作用是获取键盘输入。2 inf 和 nanfloat toobig = 3.4e38 * 100.0f; float not_a_number = asin(1.2);//math.h printf("%e \t %e\n",... 阅读全文
posted @ 2014-06-18 13:22 liuxia_hust 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 1 // typesize.c -- 输出类型的大小 2 #include 3 int main(void) 4 { 5 //C99为类型大小提供一个%zd说明符 6 7 printf("Type int has a size of %u bytes. \n", sizeof(... 阅读全文
posted @ 2014-06-18 11:24 liuxia_hust 阅读(160) 评论(0) 推荐(0) 编辑