
C
jun2016425
coolnqjun@163.com
展开
-
实现字符串翻转
#include#includevoid str_reverse(char *str);void string_reverse(char *str, int length);int main(void){ int len; /* * The string str="hello!" is in heap space if * change it will occur segm原创 2016-08-05 21:23:27 · 386 阅读 · 0 评论 -
时间获取服务器程序TCP
一个简单的时间获取服务器程序 C语言代码:#include #include #include #include #include #include #define MAXLINE 128int main(int argc, char **argv){ int listenfd, connfd; struct sockaddr_in serva原创 2018-01-08 14:08:53 · 1118 阅读 · 0 评论 -
时间获取客户端程序TCP
一个简单的时间获取客户端程序 C语言代码:#include #include #include #include #define MAXLINE 1024int main(int argc, char **argv){ int sockfd, n; char recvline[MAXLINE + 1]; struct sockaddr_in se原创 2018-01-08 14:11:24 · 497 阅读 · 0 评论 -
writen 和 readn函数实现
C语言代码// 从描述符 fd 读取 n 个字节ssize_t readn(int fd, void *vptr, size_t n){ size_t nleft; ssize_t nread; char *ptr; ptr = vptr; nleft = n; while (nleft > 0){ if ( (nrea原创 2018-01-23 17:34:15 · 1056 阅读 · 0 评论 -
删除空格
面试题里面的经典题目,替换空格。 就是在给定的数组里面替换或者删除空格,我这里是删除空格 C语言代码:#include <stdio.h>#include <string.h>#include <stdbool.h>//method 1bool replace_space(char *str);// method 2bool replace_space2(char *dest, char原创 2017-08-24 16:44:12 · 326 阅读 · 0 评论 -
后置自增操作符与解引用,前置自增操作符
char a[ ] = "Hello";char *p = a;int i = strlen(a);while(i > 0){printf("%c", *p++);++i;}1 之前一直以为printf("%c", *p++);这句话是先解引用再将p指针++的,但是我还是太年轻了,不然怎么会有Hello而不是ello呢?2 但是,运算符的优先级显示后置自增操作符原创 2016-11-08 00:11:47 · 1623 阅读 · 0 评论 -
strcpy和memcpy的使用,实现字符串的循环右移,
字符串的循环右移,使用库函数strcpy,memcpy实现原创 2016-08-14 15:07:02 · 721 阅读 · 0 评论 -
itoa的实现
itoa的实现,整数转换字符串处理原创 2016-08-13 16:25:39 · 439 阅读 · 0 评论 -
ReplaceBlank
/* length is the maxsize of string */void replace_blank(char string[], int length){ if(NULL == string && length <= 0) return ; // originaLength real length of string int originaLength = 0; int原创 2016-08-31 20:46:46 · 341 阅读 · 0 评论 -
strcpy实现
#include #include char * my_strcpy(char *strDest, const char *strSrc);int main(){ char d[16] = {0}; char s[] = "hello, world!"; char *t = NULL; t = my_strcpy(d, s); printf("dest string=%s\n"原创 2016-08-08 18:16:29 · 430 阅读 · 0 评论 -
快速高效的求两个整数的平均值(忽略小数)
#include int average(int a, int b){ /* * (a&b) is the same part of number a and b, (a^b)>>1 * is half of the diference part of number a and b. * bit computing is faster than multiplication and d原创 2016-08-05 10:05:18 · 761 阅读 · 0 评论 -
快速交换2个数的值,位运算
#include int main(void){ int a = 34; int b = 78; printf("a=%d, b=%d\n", a, b); // exchange two a and b with bit operation method a = a ^ b; b = a ^ b; a = a ^ b; printf("after exchange: a原创 2016-08-05 10:16:35 · 456 阅读 · 0 评论 -
atoi实现,字符串转换成整数
atoi函数的实现,以及其中有fgets()和scanf()区别的一些使用原创 2016-08-05 14:56:20 · 708 阅读 · 0 评论 -
整数数字转读音 num2voice C语言版
搜索了一下:整数数字转读音,看到C++版的链接如下: http://blog.youkuaiyun.com/wangmxe/article/details/78910143 于是乎翻译成了C语言版的如下:因为要的比较急,所有没写注释,注释请看上面给出的链接地址int num2voice(char *dest, int dlen, int num){ char vt1[][4] = {"零...翻译 2018-03-09 11:21:37 · 820 阅读 · 0 评论