一些小问题,避免出现低级错误。

1、strcmp(s1,s2):

字符串指针不见'\0'不回头,这个常在与单个字符作比较时写着写着就忘了.

char* p_ch1="this is an example!";
char* p_ch2="h";
printf("%d ",strcmp(p_ch1+,p_ch2);
printf("%d ",strncmp(p_ch1+,p_ch2,));//若想比较"this is an example!"中第二个字符和"h"的关系,要用strncmp

参数是 const char* 型,因此 " " 与 ' '的区别要清楚,后者在strcmp语境下看做int。 " "的一定是个指针,' '看情况,可以看做数字ASCII码或字符,所以在C++的string::iterator中,判断 *it 用  ' '。

char *p_ch = "hehenmb";
strncmp(p_ch,'h',); //error
strncmp(p_ch,"h",);

2、strcpy(s1,s2):

将s2全部拷入s1''(不考虑内存),是在s1指针指向的位置处进行粘贴,s1处以及原来的s1后面的数据都消失,变成s2的内容。

下面是一个单词单数变复数的简单例子:

规定-y变成-ies,-ch/-sh变成-ches/-shes,其他都在原单词末尾+s。

char* WordTrans(char* ch){
if(!strcmp(ch,"y")){
strcpy(ch,"ies");
return ch;
}
if(!strcmp(ch,"h")){
if(!strncmp(ch-,"c" || !strncmp(ch-,"s"))){ //这个写法中,在比较ch-1时是单个比较
strcpy(ch+,"es");
return ch;
}
else{
strcpy(ch+,"s");
return ch;
}
}
else{
strcpy(ch+,"s")
return ch;
}
}
int main(){
char word[];
scanf("%s",word);
char* p_ch=word;
WordCmp(p_ch+strlen(word)-);
printf("%s\n",word);
return ;
}

先这样了,以后再补。

字符串相关函数-strcpy()与strcmp()的更多相关文章

  1. 转:C语言字符串操作函数 - strcpy、strcmp、strcat、反转、回文

    转自:C语言字符串操作函数 - strcpy.strcmp.strcat.反转.回文 C++常用库函数atoi,itoa,strcpy,strcmp的实现 作者:jcsu C语言字符串操作函数 1. ...

  2. C语言字符/字符串相关函数收藏

    字符串的声明与使用 定义一个可变的字符串: char ch[]={"123456abc"}; char ch2[5]={"123456789"}; //会出现警 ...

  3. 不使用库函数、自己编写的(strlen、strcpy、strcmp、strcat、memcmp、memcpy、memmove)

    不使用库函数.自己编写的(strlen.strcpy.strcmp.strcat.memcmp.memcpy.memmove) //求字符串长度的函数 int my_strlen(const char ...

  4. 逆向 string.h 函数库 memset、strcpy、strcmp 函数

    memset 函数 函数原型:void *memset(void *str, int c, size_t n) 主要功能:复制字符 c(一个无符号字符)到参数 str 所指向的字符串的前 n 个字符 ...

  5. Perl函数:字符串相关函数

    Perl字符串相关函数 字符串的内置函数有: chomp, chop, chr, crypt, fc, hex, index, lc, lcfirst, length, oct, ord, pack, ...

  6. db2字符串相关函数的使用

    db2字符串相关函数的使用 from :internet    一.字符转换函数 1.ASCII() 返回字符表达式最左端字符的ASCII 码值.在ASCII()函数中,纯数字的字符串可不用‘’括起来 ...

  7. 字符串处理strcpy strcat函数的用法

    C语言函数字符串处理strcpy strcat函数的用法: 1)strcat是用来连接两个字符串的,原型是char *strcat(char *dest,char *src),作用是把src所指字符串 ...

  8. 009.Python字符串相关函数

    字符串相关函数 1 capitalize 字符串首字母大写 strvar = "this is a dog" res = strvar.capitalize() print(res ...

  9. 字符串操作函数<string.h>相关函数strcpy,strcat,等源码。

    首先说一下源码到底在哪里找. 我们在文件中包含<cstring>时,如果点击右键打开文档, 会打开cstring,我们会发现路径为: D:\Program Files\visual stu ...

随机推荐

  1. 【C语言】输入一个整数N,求N以内的素数之和

    [C语言]输入一个整数N,求N以内的素数之和 /* ========================================================================== ...

  2. 千图网爬图片(BeautifulSoup)

    import requests from bs4 import BeautifulSoup import os #导入os模块 class TuKuSpider(): ""&quo ...

  3. Gradle发布项目到 maven 之novoda/bintray-release(3)

    novoda/bintray-release 使用这个插件上传比较简单,只需要两步就可以 1.在项目根目录下的 build.gradle 添加插件依赖 // Top-level build file ...

  4. oracle 基础知识(四) 构成

    一, oracle服务 一个oracle 服务由一个oracle 实例和一个oracle数据库组成. oracle = instance + database 总体概念: 二, oracle 实例 0 ...

  5. Murano Weekly Meeting 2016.08.23

    Meeting time: 2016.August.23 1:00~2:00 Chairperson:  Kirill Zaitsev, from Mirantis Meeting summary: ...

  6. vim配置clojure开发环境备忘录

    1 需要使用的插件 vundle 使用教程 http://www.cnblogs.com/respawn/archive/2012/08/21/2649483.html vim-fireplace h ...

  7. Eclipse error: “The import XXX cannot be resolved”

    解决 Eclipse error: “The import XXX cannot be resolved” eclipse中修改: 1. 项目-->Properties-->java bu ...

  8. HDU 1069—— Monkey and Banana——————【dp】

    Monkey and Banana Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. Java学习第二十三天

    1:多线程(理解) (1)多线程:一个应用程序有多条执行路径 进程:正在执行的应用程序 线程:进程的执行单元,执行路径 单线程:一个应用程序只有一条执行路径 多线程:一个应用程序有多条执行路径 多进程 ...

  10. sql server数据库打不开