您的位置:首页 > 编程语言 > C语言/C++

华清远见c语言学习笔记一

2012-07-06 20:28 155 查看
/*

* test.c

*

* Created on: Jul 6, 2012

* Author: 孙旭

* 华清实验室

*/

/*********1**********/

#include<stdio.h>

static void fun(); //加static表示只能在该文件下使用fun()函数

void fan();

int main()

{

fun();

return 0;

}

void fan()

{

printf("this is fan()\n");

}

static void fun()

{

fan();

printf("this is fun()\n");

}

*******2********

#include<stdio.h>

int main()

{

printf("asdffgyhgfsdfsdf"); //可以使用printf("字符串/字符串变量")直接打印

return 0;

}

/********3*********/

#include<stdio.h>

#include<stdlib.h>

int main()

{

int k;

k=true; //‘true’ undeclared (first use in this function)

printf("%d",k); //在c语言中不能直接使用true/false编译器不识别

return 0;

}

/********4*********/

#include<stdio.h>

#include<string.h>

int main()

{

string h="sdfdfg"; //Multiple markers at this line

puts(h); //在c语言中不能使用string字符串,这是c++中的

return 0;

}

/********5*********/

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

int main()

{

char a[34]="abcde";

char b[]="fght";

char *c;

int i=sizeof(c); //指针的长度都是4

printf("%d\n",i);

printf("strcat=%s\n",strcat(a,b)); //把b连接到a的后面返回的是a的地址

printf("strcpy=%s\n",strcpy(a,b)); //把b整体拷贝到a中

printf("strnpy=%s\n",strncpy(a,b,2)); //把b中的前两二字符拷贝到a中的前两个字节

int k;

int j;

int h;

j=strlen(a); //使用strlen()函数测字符串实际长度,遇到‘\0‘就结束

k=strcmp(b,a); //使用strcmp函数比较大小,b大于a返回1,b小于a返回-1,b等于a返回0

h=sizeof(a); //使用sizeof()函数测存储空间的长度

printf("sizeof=%d\n",h);

printf("strcmp=%d\n",k);

printf("strlen=%d\n",j);

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: