字符串比较 [英] String Comparison

查看:121
本文介绍了字符串比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C的新人。

我有一个代码,从行中读取第一个字,这里是一块:

I am new to C.
I have a code that reads first word from the line, Here is a piece of it:

scanf(Line, "%s", Word);
printf("%s\n", Word);

此代码读取并打印行中的第一个单词。但是,我需要将该行的第一个字与另一个字进行比较。有任何建议吗?

This code reads and prints the first word in the line. However, I need to compare the first word of the line to another word. Any suggestions?

推荐答案

strcmp(str1,str2)
将C字符串str1与C字符串str2进行比较。
此函数开始比较每个字符串的第一个字符。如果它们彼此相等,则继续以下对,直到字符不同或直到达到终止的空字符。

strcmp(str1,str2) Compares the C string str1 to the C string str2. This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ or until a terminating null-character is reached.

返回指示关系的整数值


  1. 零值表示两个字符串相等。

  2. 大于零表示不匹配的第一个字符在str1中的值大于在str2中的值;

  3. 小于零的值表示相反。

这篇关于字符串比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆