
C/C++执着之路
文章平均质量分 68
team2vx
这个作者很懒,什么都没留下…
展开
-
symbian视图结构 在 CCoeControl中怎样切换到其他视图
在symbian中我们经常会用到视图结构(view-architecture),而且经常要从一个视图切换到另一个视图,比如在一个container中时如果要切换到其他视图,象这样是肯定不行:YOURCONTAINER.hCYOURAppUi * appUi;YOURCONTAINER.cppTKeyResponse CYOURContainer::OfferKeyEventL(const TK原创 2007-08-23 17:02:00 · 952 阅读 · 0 评论 -
字符串指针与字符数组
很多刚从C转C++的人都不明白,在C中这样的代码char *pChar="hELLO!"; //定义字符指针pChar,指向一个字符数组首元素即h*pChar=H; //问题所在行到了C++中怎么就不行了?你翻遍参考书,都会说,pChar指向的是常量,怎么能允许改变呢?你又问了,怎么我在C中运行的好好的?没人回答你。于是,你只好自我安慰,这就是C++的转载 2007-11-24 20:02:00 · 737 阅读 · 1 评论 -
用*号组合成一个三角形
编程爱好者上的题目,一个一个收集,同样的题目做成这样太厉害了用*号组合成一个三角形!行数由键盘输入(范围为:1~20,输入超过范围,则提示出错)。如:输入一个数4,则:输出以下组合: * *** ***** *******共四行如输入的是6,则: * *** ***** ******* ********* ***********共六转载 2007-11-20 13:10:00 · 1146 阅读 · 0 评论 -
Want to be a computer scientist? Forget maths
A new book seeks to demolish the concept that computer science is rooted in mathematics and, in particular that the notion of the algorithm is fundamental to computer science. In particular, he says转载 2007-11-19 19:54:00 · 703 阅读 · 1 评论 -
void main(void) - the Wrong Thing
void main(void) - the Wrong ThingThe newsgroup, comp.lang.c, is plagued by an almost continuous discussion of whether we can or cannot use void as a return type for main. The ANSI standard says "no"转载 2007-11-19 20:54:00 · 546 阅读 · 0 评论 -
C/C++语言误区之:fflush(stdin)
1.为什么fflush(stdin) 是错的 首先请看以下程序: #include int main( void ) { int i=1; while(i) { printf("Please input an integer: "); scanf("%d转载 2007-11-19 19:47:00 · 1017 阅读 · 0 评论 -
有趣的十二球分球问题
Q:有十二个外观相同的球,有一个重量不同,不知是轻是重;有一架天平,只称三次找出坏球。 A: 一、先左右各四个: 1、若平了,说明在剩下的四个中有坏的,在天平上的八个是标准球: 从八个标准球中拿三个,剩下的四个中拿三个放天平上: (1)若平则四个中剩下的一个是坏的; (2)若不平,则可以知道坏球在四个中拿出的三个中,而且知道了是轻转载 2007-11-19 19:14:00 · 711 阅读 · 0 评论 -
由“不用第三个变量,直接交换两个变量的值”所想到的
记得曾经看过不用引进第三个变量而直接变换两个变量的值的例子。见过的两种方法如下:方法一:var a=1;var b=2;a=a+b;b=a-b;a=a-b;输出a,b可以发现两值已经交换方法二:var a=1;var b=2;a=a^b;b=a^b;a=a^b;输出a,b可以发现两值已经交换这两种方法表面看起来只是一种技巧,转载 2007-11-19 19:08:00 · 948 阅读 · 0 评论 -
通过一个文件拷贝的例子了解二进制文件的读写
先介绍函数,我们一共要用到三个函数,fopen,fread,fwrite。二进制读写的顺序是用fopen以二进制方式打开读写文件,然后使用fread和fwrite两个函数将数据写入二进制文件中。下面我们看看一个拷贝程序的源码: Copy.c: #include转载 2007-11-15 08:09:00 · 3207 阅读 · 0 评论 -
c写文件
方法一:#includemain(){ FILE *fp; int i=0; char *s="Am I right?"; fp=fopen("c://text.txt","wr"); while(*s) { printf("%c",*s); fseek(fp,i++,SEEK_SET); fprintf(fp,"%c",*s++); //++优先级高于*转载 2007-11-15 09:52:00 · 9809 阅读 · 1 评论 -
系统功能调用函数举例
#include #include #include int main(void){ char *s; char drive[MAXDRIVE]; char dir[MAXDIR]; char file[MAXFILE]; char ext[MAXEXT]; int flags; s=getenv("COMSPEC"); /* get the comspe转载 2007-11-15 07:23:00 · 679 阅读 · 0 评论 -
linux 用C语言获得CPU的占用率
/************************/ /*用C语言获得CPU的占用率*/ /************************/#include #include #include //头文件struct occupy //声明一个occupy的结构体{ char nam转载 2007-11-12 21:45:00 · 3768 阅读 · 0 评论 -
矩阵转置
#include #include int main(){int num[4][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};int x,y,temp; for(x=0;x{ for(y=x+1;y { temp=num[x][y]; num[x][y]=num[y][x];转载 2007-11-13 20:51:00 · 667 阅读 · 0 评论 -
C语言函数调用约定
在C语言中,假设我们有这样的一个函数:int function(int a,int b)调用时只要用result = function(1,2)这样的方式就可以使用这个函数。但是,当高级语言被编译成计算机可以识别的机器码时,有一个问题就凸现出来:在CPU中,计算机没有办法知道一个函数调用需要多少个、什么样的参数,也没有硬件可以保存这些参数。也就是说,计算机不知道怎么给这个函数传递参转载 2007-11-11 10:45:00 · 590 阅读 · 0 评论 -
解析“extern”
解析“extern” 1、 声明外部变量 现代编译器一般采用按文件编译的方式,因此在编译时,各个文件中定义的全局变量是互相透明的,也就是说,在编译时,全局变量的可见域限制在文件内部。下面举一个简单的例子。创建一个工程,里面含有A.cpp和B.cpp两个简单的C++源文件: //A.cpp转载 2007-11-07 20:57:00 · 519 阅读 · 0 评论 -
Forward Declarations
Forward declarations are a great way to eliminate needless compile-time dependencies. But heres an example of a forward-declaration snare... how would you avoid it?ProblemJG Question1. Forwar转载 2007-11-24 20:06:00 · 1426 阅读 · 0 评论