#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. Codeforces 547B. Mike and Feet[单调栈/队列]

    这道题用单调递增的单调栈维护每个数能够覆盖的最大区间即可. 对于   1 2 3 4 5 4 3 2 1 6 这组样例, 1能够覆盖的最大区间是10,2能够覆盖的最大区间是7,以此类推,我们可以使用单 ...

  2. USACO Party Lamps

    题目大意:一排灯有n个,有4种开关,每种开关能改变一些灯现在的状态(亮的变暗,暗的变亮)现在已知一些灯的亮暗情况,问所以可能的情况是哪些 思路:同一种开关开两次显然是没效果的,那么枚举每个开关是否开就 ...

  3. bzoj 4401 块的计数 思想+模拟+贪心

    块的计数 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 455  Solved: 261[Submit][Status][Discuss] Descr ...

  4. poj 2987 Firing

    Firing Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 10696   Accepted: 3226 Descript ...

  5. R语言入门---杂记(一)---R的常用函数

    1.nchar():查看字符串长度. 2.rev(): 给你的数据翻个个 3.sort():给你数据排个序(默认从小到大依次排列) 4.runif():产生均匀分布的随机数 #runif

  6. Lucene 6.5.0 入门Demo

    Lucene 6.5.0 要求jdk 1.8 1.目录结构: 2.数据库环境: private int id; private String name; private float price; pr ...

  7. plsql + 客户端 连接oracle数据库

    一. 目录结构D:\oracle\instantclient_11_2D:\oracle\instantclient_11_2\tnsnames.ora 二. 环境变量 NLS_LANG = SIMP ...

  8. spring-boot-nginx代理-docker-compose部署

    在本地测试,使用docker部署不用在意环境 java测试项目: web框架:spring boot 框架 项目管理:maven 数据库:redis + postgres + mongo 部署相关:n ...

  9. js动态适配移动端font-size,单位:rem

    比如:目前我手中有一张psd图,大小为640*1010,适配苹果5的手机. 方法步骤: 1.我采用font-size=10px为640*1010手机的初始像素大小:  1rem=10px: 此时psd ...

  10. Java程序的编译过程?由.java 到.class的过程?

    Javac是一种编译器,它的任务就是将Java源代码语言转化为JVM能够识别的一种语言,然后由JVM将JVM语言再转化成当前这个机器能够识别的机器语言 词法分析器:读取源代码,一个字节一个自己的读取出 ...