原型:extern int strcmp(char *s1,char * s2);
用法:#include <string.h>
功能:比较字符串s1和s2。
说明:
当s1<s2时,返回值<0
当s1=s2时,返回值=0
当s1>s2时,返回值>0
举例:
// strcmp.c
#include <syslib.h>
#include <string.h>
main()
{
char *s1="Hello, Programmers!";
char *s2="Hello, programmers!";
int r;
clrscr();
r=strcmp(s1,s2);
if(!r)
printf("s1 and s2 are identical");
else
if(r<0)
printf("s1 less than s2");
else
printf("s1 greater than s2");
getchar();
return 0;
}
#define debug yes
一直不太明白,像 #define DEBUG #ifndef DEBUG #define DEBUG 这样的#define到底是什么意思?
我的理解是这样的: 这个正如#DEFINE R 3.142 同样理解R就代表了3.142 在定义#DEFINE DEBUG时,后面的内容是空的,因为我的下面程序没有出现错误:此段代码定义了一个test什么都没定义,使用cout << test <<end;时报错,而在使用我们认为不可能正确的cout << test 1 << endl;时却正确。所以test就是什么都没有。 #define DEBUG,定义没有值的DEBUG主要是用于控制调试程序的运行。当定义了DEBUG时"#ifdef DEBUG" 则执行某些调试用的代码,若把"#define DEBUG"删除了后,"#ifdef DEBUG" 就可以使程序不执行某些代码。 #define test #include "iostream.h" void main() { cout << test 1 << endl; }
参考资料:C++相关书籍 上机测试
while(1)
C和C++里面,true和false的值分别是1和0,while(1)就是while(true),条件判断直接为true,循环永远不会退出,while(0)就是while(false),条件判断直接为false,循环不会执行。