C和指针第九章的四个小代码
来源:互联网 发布:mac上的小房子 编辑:程序博客网 时间:2024/05/21 14:52
#include <stdio.h>#include <stdlib.h>#include <string.h>//作用是将那个数字按照一定格式输出9_14_15void dollars( char *dest,char const *src );int main(){ char a[100]; char b[300]; printf("请输入数字\n"); gets(a); dollars( b, a); puts(b); //printf("Hello world!\n"); return 0;}void dollars( char *dest,char const *src ){ int length, i; if( dest == NULL || src == NULL ) { return; } *dest++ = '$'; length = strlen(src); if( length >= 3 ) { for(i = length-2; i>0; ) { *dest++ = *src++; if(--i > 0 && i % 3 ==0 ) *dest++ = ','; } } else { *dest ++= '0'; } *dest++ = '.'; *dest++ = length < 2 ? '0':*src++; *dest++ = length < 1 ? '0':*src; *dest ='\0';}
#include <stdio.h>#include <stdlib.h>#include <string.h>//单词以空白字符分开,并且计算the出现的数目9_14_11int main(){ char a[100]; char *word; char const whitespace[] = " \n\r\f\t\v "; printf("输入一大句英文!\n"); gets(a); int count = 0; for( word = strtok( a, whitespace ); word != NULL; word = strtok( NULL, whitespace) ) { if( strcmp( word, "the" ) == 0 ) count+=1; } printf( "%d\n", count ); return 0;}
#include <stdio.h>#include <stdlib.h>#include <stddef.h>//类似strcpy的一个函数,但是返回的是指向目标字符串末尾的指针char *mystrcpy(char const *dest, char const *src);int main(){ char a[10]="ABC"; char b[7]="CDefg"; // char *first; //char *last; //first = strcpy(a, b); //puts(a); mystrcpy(a, b); /*int j; j = strlen (a); int i; for(i=0; i < j; i++) { printf("%c",a[i]); }*/ puts(a); return 0;}char * mystrcpy(char const *dest, char const *src){ char *m,*n; m = dest; n = src; char *p; while(( *m++ = *n++ )!='\0') ; p=(m-1); return p;}
#include <stdio.h>#include <stdlib.h>#include <stddef.h>//计算字符串的长度,也可以接受由于strnxx函数导致的没有'\0'的字符串长度,实际上就是看一个数组里有'\0'就计算那个长,否则就是数组长度int mystrlen( char const *string, int size );int main(){ char a[7]="ABC"; char b[5]="CDEFG"; strncpy(a, b, 5); int count; count = mystrlen(a, 8); printf("%d\n", count); return 0;}int mystrlen( char const *string, int size ){ int length = 0; for(length = 0; length < size; length++) { if(*string++ == '\0') break; } return length;}
阅读全文
0 0
- C和指针第九章的四个小代码
- C和指针--第九章_问题
- C和指针读书笔记(第九章)
- 【C/C++和指针】类默认生成的四个函数
- 第九章 字符串、字符和字节[C和指针]
- 《C和指针》第九章 字符串、字符和字节
- C和指针 第九章 字符串和字节
- 《C和指针》——第九章 判断回文
- C和指针第九章课后习题编程练习
- C和指针第八章的两个简单代码
- 第九章。指针的安全问题
- 【C】【笔记】《C和指针》 第六章 指针 第七章 函数 第八章 数组 第九章 字符串、字符和字节
- C和指针----->第二章(基本概念)->C执行文件的产生和代码规范
- 《c和指针》笔记--自由的c代码
- 《C和指针》第一章代码
- C和指针代码解析
- C小知识点 : 数组和指针遍历的效率
- 理解C语言指针和数组的关系的代码
- 除法逆元
- Maven上传第三方jar包
- 5、RARP逆地址解析协议
- hadoop集群及相关服务的启动、停止shell脚本
- Spring Cloud 服务治理
- C和指针第九章的四个小代码
- Node与Express开发-路由2
- 数串
- Java基础整理-多线程基础(上)
- jmeter接口测试基本使用
- springMVC+shiro+mybatis
- Excel vba 批量修改指定路径下指定名称对应的值
- 获取一个长文件路径(比如”E:\\test\\class\\php\\gre\\aaa\\abc.html”)中的文件名及其后缀
- python网络编程基础