-2 C语言学习:C语言中文网 http://c.biancheng.net/view/402.html
-1 int t = '1' - '0', t就是等于1了
0. 是 NULL, 没有 null
1. scanf
scanf方法中 获取%s %f %d 都是用空格 或tab 或回车 作为分割符;对于%c 不用空格这种分割符
gets() 是用 回车 作为 分割符
2. 字符串char[]
- char str[30] = {"c.biancheng.net"};
- char str[30] = "c.biancheng.net"; //这种形式更加简洁,实际开发中常用
- 获取字符串长度:
#include <stdio.h>
#include <string.h> //记得引入该头文件
int main(){
char str[] = "http://c.biancheng.net/c/";
long len = strlen(str);
printf("The lenth of the string is %ld.\n", len);
return 0;
}
4. 有时后有 ‘\0' 问题:C语言字符数组和字符串详解
5. strlen(array) 【内存字节为 sizeof(array)】,strcat(array1, array2), strcpy(array1, array2), strcmp(array1, array2), http://c.biancheng.net/view/1834.html
6. 指针初始化
#include <stdlib.h>
// 记录的类型:
typedef struct { long key; /* ... */ } Record;
_Bool newRecord( Record **ppRecord )
{
*ppRecord = malloc( sizeof(Record) );
if ( *ppRecord != NULL )
{
/* ...初始化新记录的成员... */
return 1;
}
else
return 0;
}
Record *pRecord = NULL;
if ( newRecord( &pRecord) )
{
/* ...pRecord现在指向了一个新的Record对象... */
}
pRecord->key = 123456L;