比较两个字符串长度,不使用strcmp函数
来源:互联网 发布:广数928tc编程说明 编辑:程序博客网 时间:2024/05/21 17:30
【描述】
编写一个程序,将两个字符串s1和s2比较,如果s1 > s2,输出一个正数;s1 = s2,输出0,;s1 < s2输出一个负数。不要使用strcmp函数。两个字符串用gets函数读入。输出的正数或者负数的绝对值应是相比较的两个字符串相应字符的ASCII码的差值。例如“A”与“C”相比,由于“A” < "C",应该输出负数,由于“A”与"C"的ASCII嘛差值为2,因此应该输出“-2”。同理:“And”和“Aid”比较,根据第二个字符比较的结果,"n”比"i"大5,因此输出5。
【C语言】
#include<stdio.h>#include<string.h>int main() {char s1[10], s2[10];gets(s1);gets(s2);int i;for (i = 0; (s1[i] != '\0') && (s2[i] != '\0'); i++)if (s1[i] == s2[i]) {continue;} else {break;}printf("%d\t", s1[i] - s2[i]);return 0;}
0 0
- 比较两个字符串长度,不使用strcmp函数
- 不使用strcmp函数比较两个字符串的大小
- strcmp和memcmp两个字符串比较函数
- 比较两个字符串【不可以使用strcmp】
- 字符串比较函数strcmp
- 比较字符串strcmp()函数
- strcmp字符串比较函数
- strcmp()字符串比较函数
- 编写字符串比较函数strcmp
- 编写字符串比较函数strcmp .
- strcmp()字符串比较函数
- 完成字符串比较函数strcmp()
- PHP字符串比较函数strcmp()和strcasecmp()使用总结
- 【C语言】模拟strcmp比较两个字符串
- 写一函数,实现两个字符串的比较,即自己写一个strcmp函数
- P279_1017 写一函数,实现两个字符串的比较,即自己写一个strcmp函数
- 【字符串比较函数】strcmp,stricmp,strcmpi区别
- 自己动手写字符串比较函数strcmp()
- 剑指offer 53-正则表达式匹配
- PHPER 如何突破成长瓶颈
- 黑马程序员-----oc语言学习笔记之内存管理二
- 一步步教你使用Proguard混淆Java源代码
- Oracle Partition分区简介
- 比较两个字符串长度,不使用strcmp函数
- Linux中Oracle的日常维护命令
- 常用排序算法之插入排序法
- Apache整合PHP+MySQL
- VC++中的WinMain()函数介绍
- Android:操作图片Exif信息
- CAPropertyAnimation 用法
- JAVA实现简单的冒泡排序与选择排序
- require.js 简洁入门