摘要: 如:int a[2][2][2] = { { {1, 2}, {3, 4} }, { {5, 6}, {7, 8} } }; int main(void){ int a[2][2][2] = { { {1, 2}, {3, 4} }, { {5, 6}, {7, 8} } }; int ***p = (int***)a; printf("The value is: %d\n", *(int*)p); return 0;} 可以用一个多级指针(3级)指向数组名,但这里其实经过了一个强制的类型转换,即(int ***),也可以这样:int***p=&a[0][0][0] 阅读全文
posted @ 2013-05-21 15:27 yurius 阅读(187) 评论(0) 推荐(0) 编辑
摘要: //已知 f(n) = f(n-1) + f(n-2) ,f(0) = 0 ,f(1) = 1。 求 f(n)#include<stdio.h>long fb_iter(int n);long fb_array[100]={0};int main(){printf("start caculate Fibonacci\n");printf("Fibonacci is %d\n",fb_iter(10));}/*递归方式*//*long fb_iter(int n){ if (0==n) return 0; if (1==n) return 1; 阅读全文
posted @ 2013-05-09 16:53 yurius 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 谭浩强绿皮书例10.28以下代码在int *num[5]={&a[0],&a[1],&a[2],&a[3],&a[4]};肯定报初始化错误。而用VS2008编译通过。原因不明。int _tmain(int argc, _TCHAR* argv[]){int a[5]={1,3,5,7,9};int *num[5]={&a[0],&a[1],&a[2],&a[3],&a[4]};int **p,i;p=num;for (i=0;i<5;i++){printf("%d",**p);p++;}p 阅读全文
posted @ 2013-02-24 14:03 yurius 阅读(159) 评论(0) 推荐(0) 编辑
摘要: fflush(stdout);可以及清空读入的缓存,谁用谁知道。fflush(FILE*)由于fread和fwrite共用一个缓存,故若不即时fflush则会有很大的问题。fflush可以立即输出。 阅读全文
posted @ 2013-02-24 13:52 yurius 阅读(214) 评论(0) 推荐(0) 编辑
摘要: 链表的插入、删除、添加,按自己想法写的代码。。。逻辑不是很明晰。。。#include<stdio.h>struct student{int score;int n;struct student *next;};struct student *creatlist(){struct student *head,*p1,*p2;head=NULL;p1=p2=(struct student *)malloc(sizeof(struct student));scanf("%d,%d",&p1->n,&p1->score);head=p1;wh 阅读全文
posted @ 2013-02-24 13:34 yurius 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 以前一直奇怪. * ./有什么用,今天测试了下。直接输入代码#include<stdio.h>void main(){float aa=10;float bb=10;aa=10. *8;bb=10. /8;printf("%f,%f",aa,bb);}输出80。000000,1.250000。可见,该运算可保留小数后面6位。、另外,即使不留空格也完全没有问题。另测了一下经常在句末风到的右斜杆\如:#define CHECK( name, limit, val ) \if( (val) > (limit) ) \ERROR( name " (%d) 阅读全文
posted @ 2013-02-24 13:32 yurius 阅读(230) 评论(0) 推荐(0) 编辑
摘要: strdup复制字符串比起strcpy,strdup可以复制给没有分配内存的指针,最后这个分给这个指针的空间释放掉(但很怪我在VC6上实验即使分配了内存,strdup依然可以进行复制,也许跟平台有关);strchr找到指定的字符,返回指向该字符的指针;strncmp比较前N个字符,相等输出0以下是vc6上的实验:#include <stdio.h>#include <string.h>void main(){char temp[32];char *s = temp;char *p,c='v';memset(temp,0,sizeof(temp));str 阅读全文
posted @ 2013-02-24 13:31 yurius 阅读(593) 评论(0) 推荐(0) 编辑
摘要: #include<stdio.h>#include<stdlib.h>#include<string.h>int main(){FILE *fp=NULL;int f_size=0;char*all=NULL;fp=fopen("0.txt","r+b");if(fp==NULL){printf("open error");system("pause");}fseek(fp,0L,SEEK_END);f_size=ftell(fp);fseek(fp,0L,SEEK_SET);a 阅读全文
posted @ 2013-02-24 13:30 yurius 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 比如下面这样char* my="youwin";char youwin[50];_snprintf(youwin,strlen(my)+strlen("结果为:")+1,"结果为:%s",my);printf("%s",youwin);return 0;注意strlen是不计算末尾的那个\0的,所以要加1. 阅读全文
posted @ 2013-02-24 13:29 yurius 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 1单步进入一些函数,随便如strcmp,就会弹出浏览路径,估计是只是编好的lib没有源码?还有void kq_free_list(struct kq_person* head){struct kq_person* p=NULL,*q=NULL;p=head->next;free(head);while(p!=NULL){q=p;p=p->next;free(q);}}这样没问题,可是直接free(p)就不行,奇怪。2直接看代码#include <stdio.h>#include <io.h>#include <fcntl.h>#include & 阅读全文
posted @ 2013-02-24 13:28 yurius 阅读(152) 评论(0) 推荐(0) 编辑