#include <stdio.h>
char* stringCopy( char* dest, const char* src )
{
    size_t i = 0;
    while (dest[i] = src[i++]);
    return dest;
}
int binary_search(int *arr, int key, int n)
{
    int i = n / 2;
    if (arr[i] < key)
    {
        for ( ++i; i < n; ++i)
        {
            if (arr[i] == key) return i;
        }
    }
    else
    {
        for (; i > -1; --i)
        {
            if (arr[i] == key) return i;
        }
    }
    return -1;
}
int main()
{
    char strBuf[100];
    char *ret = stringCopy(strBuf, "This is a test!\n这是一个测试!");
    printf("%s\n", strBuf);
    printf("%s\n", ret);
    int ints[] = { 1, 3, 5, 7, 9 };
    printf("%d\n", binary_search(ints, 5, sizeof ints / sizeof(int)));
    printf("%d\n", binary_search(ints, -1, sizeof ints/ sizeof(int)));
    printf("%d\n", binary_search(ints, 9, sizeof ints/ sizeof(int)));
    printf("%d\n", binary_search(ints, 3, sizeof ints/ sizeof(int)));
    return 0;
}

char* strcpy( char* dest, const char* src ), int binary_search(int *arr, int key, int n), 可能的实现的更多相关文章

  1. char * p = "abc"与const char *p = "abc"

    char * p = "abc"与const char *p = "abc"的区别是什么呢? 第一个语句会产生问题: warning: deprecated c ...

  2. void *memmove( void* dest, const void* src, size_t count );数据拷贝,不需要CPU帮助

    分享到 腾讯微博 QQ空间 新浪微博 人人网 朋友网 memmove 编辑词条 编辑词条 -->   memmove用于从src拷贝count个字符到dest,如果目标区域和源区域有重叠的话,m ...

  3. 用C语言实现一个公用库函数void * memmove(void *dest,const void *src,size_t n)

    用C语言实现一个公用库函数void * memmove(void *dest,const void *src,size_t n). 该函数的功能是拷贝src所指的内存内容前n个字节到dest所指的地址 ...

  4. 字符串复制char *strcpy(char* dest, const char *src);

    ⒈strcpy的实现代码 char * strcpy(char * strDest,const char * strSrc) { if ((NULL==strDest) || (NULL==strSr ...

  5. C/C++中char* p = "hello" 和 const char* p = "hello"的区别

    在写代码常常都会写char * p ="hello";这样的代码,虽然不是错误,但却不建议这样用.应该加const修饰.这句话背后的内涵是什么?下面就刨根问底一下:) 这个行为在不 ...

  6. C++ char*,const char*,string,int 的相互转换

    C++ char*,const char*,string,int 的相互转换   1. string转const char* string s ="abc";const char* ...

  7. (c++) int 转 string,char*,const char*和string的相互转换

    一.int 和string的相互转换 1 int 转化为 string c++ //char *itoa( int value, char *string,int radix); // 原型说明: / ...

  8. 【C++】int、const char*、char*、char、string之间的转换

    #include "stdafx.h" #include<string> #include<vector> #include<iostream> ...

  9. C语言执行时报错“表达式必须是可修改的左值,无法从“const char [3]”转换为“char [120]” ”,原因:字符串不能直接赋值

    解决该问题的方法:使用strcpy函数进行字符串拷贝   原型声明:char *strcpy(char* dest, const char *src); 头文件:#include <string ...

随机推荐

  1. 【bzoj1109】[POI2007]堆积木Klo 动态规划+树状数组

    题目描述 Mary在她的生日礼物中有一些积木.那些积木都是相同大小的立方体.每个积木上面都有一个数.Mary用他的所有积木垒了一个高塔.妈妈告诉Mary游戏的目的是建一个塔,使得最多的积木在正确的位置 ...

  2. HDU——3786找出直系亲属(DFS+回溯)

    找出直系亲属 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  3. C 语言中可以调用命令行指令的 system()函数

    C语言有一个system函数(在<stdlib.h>头中,C++则为<cstdlib>头),可以用来调用终端命令.原型如下: int system(const char *cm ...

  4. Nk 1430 Fibonacci(二分矩阵乘幂)

    AC代码: #include<iostream> using namespace std; ][]; ][]; ][]; ][]; void binary(int n) { int i,j ...

  5. 圆桌聚餐(cogs 729)

    «问题描述:假设有来自m 个不同单位的代表参加一次国际会议.每个单位的代表数分别为ri(i=1,2,3...m), .会议餐厅共有n张餐桌,每张餐桌可容纳c i(i=1,2...n) 个代表就餐.为了 ...

  6. 洛谷 [P4151] 最大异或和路径

    线性基 首先我们发现,对于一条路径走过去再走回来是没有意义的, 所以我们可以没有任何其他影响的取得一个环的异或和 所以我们预处理出来所有环的异或和,求出他们的线性基,然后任找一条 \(1 \sim n ...

  7. ElasticSearch中Date

    ElasticSearch中有时会想要通过索引日期来筛选查询的数据,此时就需要用到日期数学表达式. 比如现在的时间是2024年3月22日中午12点.utc 注意,如果是中国的时间需要加上8个小时! 表 ...

  8. 标准C程序设计七---05

    Linux应用             编程深入            语言编程 标准C程序设计七---经典C11程序设计    以下内容为阅读:    <标准C程序设计>(第7版) 作者 ...

  9. spl_autoload_register() && __autoload函数

    一.__autoload 这是一个自动加载函数,在PHP5中,当我们实例化一个未定义的类时,就会触发此函数. 在index.php中,由于没有包含test.class.php,在实例化printit时 ...

  10. ftrace用法

    ftrace官方文档在kernel/Documentation/trace/ftrace.txt文件中. 使用ftrace接口之前,如果系统没有自动挂载debugfs文件系统,则要先手动挂载. # m ...