![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C语言
崖高人远
这个作者很懒,什么都没留下…
展开
-
结构体指针
//结构体指针#include //定义结构Person用来描述人,其中包含一个函数指针用来表示当前这个人的生长方式typedef struct{ unsigned short age; //用pGrow函数指针记录每个人自己的生长方式 void (*pGrow)(void * pPerson);}Person;//正常人的生长方式,今年20明年21.参数是代表了某个人的结构提转载 2012-09-22 11:21:24 · 619 阅读 · 1 评论 -
函数指针
//函数指针#include int add(int x,int y){ return x + y;}int mul(int x,int y){ return x * y;}int main(){ //声明一个函数指针变量 //声明语法类似函数函数声明 int (*pFunc)(int,int); pFunc = add; printf("add:%p\n",a转载 2012-09-22 10:00:28 · 260 阅读 · 0 评论 -
枚举,结构体、、
#include typedef enum{ SI, //这个枚举表示单牌 DO //这个枚举表示对牌}CardType;typedef enum{ GT, //这个表示大于 EQ, //这个表示等于 LT, //这个表示小于 IC //这个表示不能比较}ResultType;typedef struct{ CardType type; unsigned转载 2012-09-22 12:08:28 · 321 阅读 · 0 评论 -
枚举,结构体、、、
#include typedef enum{ SI, //这个枚举表示单牌 DO //这个枚举表示对牌}CardType;typedef enum{ GT, //这个表示大于 EQ, //这个表示等于 LT, //这个表示小于 IC //这个表示不能比较}ResultType;typedef struct{ CardType type; unsigned shor转载 2012-09-22 14:04:29 · 336 阅读 · 0 评论 -
数组指针
//数组指针#include int main(){ int values1[5] = {1,2,3,4,5}; int (*pValues1)[5]; //输出的结果为什么是这样的? pValues1 = &values1; //赋给pValues的是二级指针? printf("pValues1地址是:%p\n",pValues1); printf("values1地址是:%转载 2012-09-22 18:40:24 · 286 阅读 · 0 评论 -
文件的打开、关闭
//文件的打开,关闭#include int main(){ FILE * pFile = fopen("a.txt","w"); if (NULL != pFile) { fclose(pFile); pFile = NULL; } return 0;}转载 2012-09-22 18:41:23 · 322 阅读 · 0 评论 -
文件的打开、写入、关闭
//文件的打开,写入,关闭#include int main(){ char str[] = "Hello World!"; FILE * pFile = fopen("a.txt","w"); if (NULL != pFile) { int pos = 0; while ('\0' != str[pos]) { //int fputc(char ch,File转载 2012-09-22 18:42:17 · 335 阅读 · 0 评论 -
使用fwrite函数向文件写入数据
//使用fwirte函数向文件写入数据//写入的数据无法用more或者cat查看#include int main(){ int values[5] = {5,6,7,8,9}; FILE *pFile = NULL; pFile = fopen("c.txt","w"); if (NULL != pFile) { //size_t fwrite(const void* bu转载 2012-09-22 18:44:42 · 2156 阅读 · 0 评论 -
使用fseek函数,重新定位文件内部的位置指针
//使用fseek函数重新定位文件内部的位置指针#include int main(){ int values[5] = {0}; FILE *pFile = NULL; int loop = 0; pFile = fopen("c.txt","rb"); if (NULL != pFile) { for (loop = 0; loop <= 4; loop++) {转载 2012-09-22 18:47:58 · 893 阅读 · 0 评论 -
使用fread函数读取文件里的数据
//使用fread函数读取文件里的数据#include int main(){ int values[5] = {0}; FILE *pFile = NULL; int loop = 0; //注意模式:rb pFile = fopen("c.txt","rb"); if (NULL != pFile) { //size_t fread(void *buff,size_t转载 2012-09-22 18:45:29 · 3055 阅读 · 0 评论 -
关于这个就完全没有印象了。
//关于这个就完全没有印象了。//#include #include int max(int cnt,...);int main(){ printf("%d\n",max(2,58,36)); printf("%d\n",max(4,5,97,26,108)); return 0;}int max(int cnt,...){ va_list v; va_start(转载 2012-09-23 12:01:54 · 358 阅读 · 0 评论 -
sprintf sscanf
//sprintf sscanf#include int main(){ char str[30] = {0}; int value = 5; char aChar = 'a'; float aFloat = 2.4; sprintf(str,"%d %c %f",value,aChar,aFloat); printf("%s\n",str); value = 0; a转载 2012-09-23 12:01:12 · 293 阅读 · 0 评论 -
指针数组
#include int main(){ int * pValues[3]; int firstValue[3] = {3,4,5}; int secondValue[4] = {6,7,8,9}; int thirdValue[4] = {10,11,12,13}; pValues[0] = firstValue; pValues[1] = secondValue; pValu转载 2012-09-22 16:24:35 · 255 阅读 · 0 评论 -
数组指针,排序算法
#include #include int main(){ //这是指针数组的初始化来着? //五个元素其实都是指向五个字符串的收地址的指针? char * strs[5] = {"japan","china","america","britain","australia"}; int outloop = 0; int inloop = 0; //这种排序叫啥来着? //这里结转载 2012-09-22 16:53:21 · 361 阅读 · 0 评论 -
文件的打开、读取、关闭
//文件的打开,读取,关闭#include int main(int argc,char* argv[]){ if (argc < 2) { printf("usage:11fileread file\n"); return 0; } //这里曾经有一个错误,居然把r写成1 FILE * pFile = fopen(argv[1],"r"); if (NULL != p转载 2012-09-22 18:43:06 · 351 阅读 · 0 评论 -
两个文件之间的打开、读写、关闭
//两个文件之间的打开、读写、关闭#include int main(int argc,char * argv[]){ if( argc < 3) { printf("usage: xxx \n"); return 0; } FILE * pSrcFile = NULL; FILE * pDestFile = NULL; pSrcFile转载 2012-09-22 18:43:47 · 343 阅读 · 0 评论 -
使用rewind函数,重新定位文件内部的位置指针
//rewind函数,重新定位文件内部的位置指针#include int main(){ int values[5] = {0}; FILE * pFile = NULL; int loop = 0; pFile = fopen("c.txt","rb"); if (NULL != pFile) { for (loop = 0; loop <= 4; loop++) {转载 2012-09-22 18:46:38 · 857 阅读 · 0 评论 -
fseek fread 指定文件指针位置开始读取数据
//fseek fread 指定文件指针位置开始读取数据#include int main(){ FILE * pFile = NULL; pFile = fopen("c.txt","rb"); if (NULL != pFile) { int value; fseek(pFile,0,SEEK_SET); //奇怪的是这里读取超过1个元素就会段错误 fread转载 2012-09-23 11:53:56 · 4447 阅读 · 0 评论 -
结构体,fopen,fwrite,fread,fclose 文件打开、写入、读取、关闭
//结构体,fopen,fwrite,fread,fclose 文件打开、写入、读取、关闭#include typedef struct{ unsigned short age; float height; float weight;}Person;int main(){ Person persons[3] = {{21,1.78,73.6},{19,1.65,49},{70转载 2012-09-23 11:57:04 · 823 阅读 · 0 评论 -
fprintf函数格式化数据
//fprintf函数格式化数据#include int main(){ int value = 5; char aChar = 'a'; float aFloat = 5.6; FILE *pFile = NULL; //写入方式是否是二进制? //可以使用more、cat命令查看e.txt pFile = fopen("e.txt","w"); if (NULL !=转载 2012-09-23 11:59:38 · 448 阅读 · 0 评论 -
fscanf格式化输入,文件的打开,读取,关闭
//fscanf格式化输入,文件的打开,读取,关闭#include int main(){ int value = 0; char aChar = 0; float aFloat = 0; FILE * pFile =NULL; pFile = fopen("e.txt","r"); if (NULL != pFile) { fscanf(pFile,"%d %c %f"转载 2012-09-23 12:00:29 · 542 阅读 · 0 评论 -
常量指针和指针常量
#include int main(){ int values[5] = {1,2,3,4,5}; const int * pValue1 = values; pValue1 += 3; //编译成功 //pValue[0] = 7; //编译出错 int * const pValue2 = values; //pValue2 += 3;转载 2012-09-22 09:49:12 · 265 阅读 · 0 评论