无法在用户定义的函数中调用库函数

阿西什·库沙吉

我正在 c 中创建 strcmp() 的用户定义函数。

#include <stdio.h>
#include <string.h>
int la,lb;    // la and lb for length of 2 strings
 
int scompare(char [],char []);

int main() {

 char a[50],b[50];     // a and b are 2 strings

printf("Enter 2 strings \n");
gets(a);
gets(b);
la =strlen(a);
lb =strlen(b);
printf("%d",scompare(a,b));

 }
 int scompare(char a[la],char b[lb])
   {
     for(int i=0 ;i<max(la,lb);i++)
     { // loop for comparing characters of 2 strings

       // here in vs code it is showing error --->
       // warning: implicit declaration of function 'max' [-Wimplicit-function-declaration]

for(int i=0 ;i<max(la,lb);i++)

         int k = a[i]-b[i];// k is the sum of ascii of characters of a and b
   
         if(k!=0 &&toupper(a[i])==toupper(b[i]))
         return (k>0)?1:-1;

         // other error is showing here in function toupper --->  warning: implicit declaration of function 'toupper' [-Wimplicit-function-declaration]

if(k!=0 &&toupper(a[i])==toupper(b[i])) 

         else if(k!=0)
        return k;
    
    }
  return 0;
 } 
来自莫斯科的弗拉德

在调用函数之前,您需要提供它的声明,该声明可以出现在例如标题中。

maxC 中没有标准函数,你需要自己编写这样的函数。

要使用标准功能,toupper您需要包含标题<ctype.h>

#include <ctype.h>

这个循环(如果假设函数max是在某处定义的)

for(int i=0 ;i<max(la,lb);i++)

可以调用未定义的行为,则字符串的长度彼此不相等。

注意该函数gets不是标准的 C 函数。这是不安全的。你应该使用fgets.

而这个函数声明

int scompare(char a[la],char b[lb]);

没有意义。

该函数应声明为

int scompare( const char a[], const char b[] );

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Javascript中的自定义库函数中调用函数

调用用户定义的数据库函数

在用户定义的函数内调用glm()函数

KeyError:在用户定义的函数中

如何在用户定义的函数中避免重复

在用户定义的函数中声明表变量

在用户定义的函数中访问全局文件

Python方法未显示在用户定义的函数中

使用 reshape2::melt 和 reshape2::dcast 在用户定义函数中调用变量

在用户定义函数中使用RAND()

在用户定义函数中使用模块

在用户定义函数中使用标志

使用C#调用按钮的自定义库函数

SQL中用户定义函数中的调用函数

在用户定义的函数format上调用println从main返回3次,但是执行顺序不同

如何在用户空间中调用自定义内核函数?

如何在用户定义的函数中使用AQL函数?

为什么在用C ++调用函数之前需要函数定义?

无法在Polymer中进行用户定义的函数调用

BigQuery 用户定义函数错误 - 无法在查询中调用 UDF

如何在Go中调用linux共享库函数?

在框架之外的PHP文件中调用OpenCart库函数

棒棒糖中未调用共享库函数

从Visual Studio中的asm调用C标准库函数

vue.js 外部库函数在组件中调用

在MarkLogic中从Schematron调用外部API和库函数

如何从 PHP 中的另一个用户定义函数调用用户定义函数

如何从bash中的另一个用户定义函数调用用户定义函数?

在另一个用户定义函数中调用SQL用户定义函数