03 2013 档案
摘要:复试终于结束了,唉。。一言难尽 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 void test1_1_swap(char *pa, char *pb) 5 { 6 //由于传入的实参是数组地址,它是一个char* const类型, 7 //即数组的首地址是无法被修改的,所以这种直接交换首地址的方法是不可行的 8 //char *temp; 9 //temp = pa; 10 //pa = pb; 11 //pb = temp; 12 ...
阅读全文
摘要:1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { 6 int i = 1, j = 1; 7 for(; i <= 5; i++) 8 { 9 for(j = 1; j <= 5 - i; j++)10 {11 printf("%s", " ");12 }13 for(j = 1; j <= 2 * i - 1; j++)14 {15 printf("%s", "*...
阅读全文
摘要:C语言中sizeof是一个运算符,strlen是string.h中的库函数sizeof计算的是变量申请的内存空间大小,strlen计算的是数组从第一个位置到'\0'所占的内存大小 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 5 void fun(char* a) 6 { 7 printf("fun:: sizeof(a) = %d\tstrlen(a) = %d\n", sizeof(a), strlen(a)); 8 int i =
阅读全文
摘要:1 #include <stdio.h> 2 #include <stdlib.h> 3 #define A_SCREEN 5 //每次输出的行数 4 #define MAX_CHAR_EACH_LINE 100 //每行最大字符数 5 int main() 6 { 7 FILE *fp; 8 if(NULL == (fp = fopen("test", "r"))) 9 {10 printf("file dosen't exist!");11 return -1;12 }13 int count;14
阅读全文
摘要:1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #define MAX_CHAR_EACH_LINE 20 // 每行最大的字符数 5 int main(int argc, char *argv[]) 6 { 7 FILE *fp1, *fp2; 8 if((fp1 = fopen("test1", "r")) == NULL) 9 {10 return -1;11 }12 if((fp2 = fopen("test2&qu
阅读全文
摘要:今天发现一个奇怪的现象,写了一个c程序,用gcc编译器编译,居然没有报错,而且还能正常运行看代码: 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { 6 char *p = (char*)malloc(1); //申请了一个很小的空间 7 printf("len is %d\n", strlen(p));//打印p所指的大小 8 printf("addr:0x%x\n", (int)p);//打印p所指的内存地址 9 gets(p);//从键盘读入一行字符1
阅读全文
摘要:1. 求数组next[j]的算法如下,它只与模式串有关,与目标串无关 1 void cal_next(char *p, int *next, int len) 2 {//important!! array rangs from 0 to len-1 3 int i = -1, j = 0;//i == -1 means back to the first elem of p[]; 4 next[0] = -1; 5 //except first element, next[j]=k means that before j, there are k elem match...
阅读全文
摘要:共用体很少用,今天遇到一个问题: 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 int main() 5 { 6 union EXAMPLE 7 { 8 struct 9 {10 int x;11 int y;12 } in;13 int a;14 int b;15 } e;16 e.a=1;17 e.b=2;18 e.in.x=e.a*e.b;19 e.in.y...
阅读全文
摘要:hard linkhard link是linux中的一种文件共享方式,它的原理是共享inode。当建立一个hard link时,inode的共享计数加1,删除时减1(若减为0,则删除文件)。建立hard link0. 命令格式: ln src_file dis_file1. 源文件file.src, inode = 519777, 共享计数 = 12.lnfile.src file.hardlink文件file.hardlink, inode = 519777(与源文件相同), 共享计数 = 2注意1. inode相同意味着两个文件是完全等效的,只是名字不一样。(可以理解为对不同的文件取了各种
阅读全文

浙公网安备 33010602011771号