int fun(const char *s1, const char *s2);用法要使用 fun 函数比较两个字符串,需要以下步骤:立即学习“C语言免费学习笔记(深入)”;包含头文件 。声明两个">

c语言fun函数怎么用

来源:这里教程网 时间:2026-02-21 16:49:50 作者:

如何使用 C 语言的 fun 函数

fun 函数是 C 语言中一个标准库函数,用于比较两个字符串是否相等。其原型如下:

<code class="c">int fun(const char *s1, const char *s2);</code>

用法

要使用 fun 函数比较两个字符串,需要以下步骤:

立即学习“C语言免费学习笔记(深入)”;

    包含头文件
    <string.h></string.h>
    声明两个指向字符串的常量指针,其中一个指向第一个字符串,另一个指向第二个字符串。 调用 fun 函数,传递两个字符串指针作为参数。

    检查 fun 函数返回的值:

    如果返回 0,表示两个字符串相等。 如果返回一个非零值,表示两个字符串不相等。

示例

以下示例演示如何使用 fun 函数比较两个字符串:

<code class="c">#include <stdio.h>
#include <string.h>
int main() {
  const char *str1 = "Hello";
  const char *str2 = "World";
  int result = fun(str1, str2);
  if (result == 0) {
    printf("The strings are equal.\n");
  } else {
    printf("The strings are not equal.\n");
  }
  return 0;
}</code>

输出

<code>The strings are not equal.</code>

相关推荐