1、编写函数,把由十六进制数字组成的字符串转换为对应的整型值

编写函数htoi(s),把由十六进制数字组成的字符串(包含可选的前缀0x或0X)转换为与之等价的整型值。字符串中允许包含的数字包括:0~9、a~f 以及 A~F。

#define YES 1
#define NO 0 /* htoi: convert hexadecimal string s to integer */
int htoi(char s[])
{
int hexdigit, i, inhex, n; i = 0;
if(s[i] == '0') // skip optional 0x or 0X
{
++i;
if(s[i] == 'x' || s[i] == 'X')
++i;
} n = 0; // integer value to be returned
inhex = YES; // assume valid hexadecimal digit
for( ; inhex == YES; ++i)
{
if(s[i] >= '0' && s[i] <= '9')
hexdigit = s[i] - '0';
else if(s[i] >= 'a' && s[i] <= 'f')
hexdigit = s[i] - 'a' + 10;
else if(s[i] >= 'A' && s[i] <= 'F')
hexdigit = s[i] - 'A' + 10;
else
inhex = NO; // not a valid hexadecimal digit
if(inhex == YES)
n = 16 * n + hexdigit;
} return n;
}

2、编写函数,将字符串s1中任何与字符串s2中字符匹配的字符都删除

/* squeeze: delete each char in s1 which is in s2 */
void squeeze(char s1[], char s2[])
{
int i, j, k; for(i = k = 0; s1[i] != '\0'; i++)
{
for(j = 0; s2[j] != '\0' && s2[j] != s1[i]; j++)
;
if(s2[j] == '\0') // end of string - no match
s1[k++] = s1[i];
}
s1[k] = '\0';
}

3、编写函数, 将字符串s2中的任一字符在字符串s1中第一次出现的位置作为结果返回

编写函数any(s1, s2), 将字符串s2中的任一字符在字符串s1中第一次出现的位置作为结果返回。如果s1中不包含s2中的字符,则返回-1。(标准库函数strpbrk具有同样的功能,但它返回的是指向该位置的指针。)

/* any: return first location in s1 where any char from s2 occurs */
int any(char s1[], char s2[])
{
int i, j; for(i = 0; s1[i] != '\0'; i++)
for(j = 0; s2[j] != '\0'; j++)
if(s1[i] == s2[j]) // match found?
return i; // location first match
return -1; // otherwise, no match
}

Getting started with the basics of programming exercises_5的更多相关文章

  1. Getting started with the basics of programming exercises_4

    1.编写一个删除C语言程序中所有的注释语句的程序.要正确处理带引号的字符串与字符串常量,C语言中程序注释不允许嵌套. #include<stdio.h> void rcomment(int ...

  2. Getting started with the basics of programming exercises_3

    1.编写一个程序删除每个输入行末尾的空格及制表符并删除完全是空白符的行 #include<stdio.h> #define MAXLINE 1000 // maximum input li ...

  3. Getting started with the basics of programming exercises_2

    1.编写简单power函数 #include<stdio.h> int power(int m, int n); // test power function int main(void) ...

  4. Getting started with the basics of programming exercises_1

    1.编写一个将输入复制到输出的程序,并将其中连续的多个空格用一个空格代替 使用if 结构: #include<stdio.h> #define NONBLANK 'a'; // repal ...

  5. Beginning C# Programming with Unity

    Welcome to the wonderful world of programming! In this book you’ll learn the basics of programming u ...

  6. C语言学习书籍推荐《Practical C++ Programming》下载

    下载链接 :点我 C++ is a powerful, highly flexible, and adaptable programming language that allows software ...

  7. How do I learn machine learning?

    https://www.quora.com/How-do-I-learn-machine-learning-1?redirected_qid=6578644   How Can I Learn X? ...

  8. LINQ Query Expressions

    https://msdn.microsoft.com/en-us/library/bb397676(v=vs.100).aspx Language-Integrated Query (LINQ) is ...

  9. 【译】微软的Python入门教程(一)

    Getting started with Python(Python入门) Overview 概述 The series of videos on Channel 9 is designed to h ...

随机推荐

  1. SELECT (@i :=@i + 1)生成序列号

    转载自https://blog.csdn.net/qq_27922171/article/details/86477544 同类别自动生成序列号:https://bbs.csdn.net/topics ...

  2. SpringBooot-基础<2>-POM.xml配置

    SpringBooot-基础<2>-POM.xml配置 项目创建完成后,需要配置pom.xml文件. pom.xml里面的配置,按需进行添加,这里提供一份参考,后面做笔记会都用到. < ...

  3. Struts_添加客户练习

    1.修改CustomerAction,实现ModelDriven接口 2.修改配置文件 3.修改表单提交地址

  4. Dreamweaver CS5更改代码颜色方法代码

    XP系统下: C:\Documents and Settings\Administrator\ApplicationData\Adobe\Dreamweaver CS4\zh_CN\Configura ...

  5. 阿里云Global Connection亮相MWC 2019,做企业全球化开路先锋

    上周在巴塞罗那举行的MWC 2019世界移动通信大会上,阿里云发布了包含Global Connection解决方案在内的7款重量级产品和解决方案,为全球企业提供了基于阿里云的智能化企业数字转型思路.G ...

  6. qq在线

    <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=1749904992&site=q ...

  7. Django创建对象的create和save方法

    Django的模型(Model)的本质是类,并不是一个具体的对象(Object).当你设计好模型后,你就可以对Model进行实例化从而创建一个一个具体的对象.Django对于创建对象提供了2种不同的s ...

  8. babel 7.x 结合 webpack 4.x 配置

    今天在学习webpack的使用的时候,由于学习的教程是2018年初的,使用的是 webpack 3.x 和 babel 6.x ,然后学习的过程中出现的了很多问题. 解决问题之后,总结一下新的 bab ...

  9. linux系统命令配置文件

    系统命令要独占地控制系统,并让一切正常工作.所有如 login(完成控制台用户身份验证阶段)或 bash(提供用户和计算机之间交互)之类的程序都是系统命令.因此,和它们有关的文件也特别重要.这一类别中 ...

  10. JQuery--关系选择器

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...