gpt4 book ai didi

c - 错误: too few arguments to function 'strcmp'

转载 作者:行者123 更新时间:2023-11-30 17:36:46 31 4
gpt4 key购买 nike

我的代码有一些问题。首先:当我尝试编译时,我收到错误:函数'strcmp'的参数太少。我已经查看了所有内容并进行了多次更改,但仍然无法使其工作。第二:当我的代码编译时(如果我删除 strcmp 部分),它将无法正确完成计数函数。有人可以帮忙吗?谢谢你!

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int count(char array[], int size);
int stringLen(char array[]);
int convert(char ch);
int value, n;

int main()
{
//char * str;
//char s;
char a[100];
char b[100];
char c[100];
int charCount = stringLen(a);
int lCount = count(a, charCount);
printf("Enter your string: \n");
scanf("%s \n", a);
printf("Enter your string: \n");
scanf("%s \n", b);
printf("Enter your string: \n");
scanf("%s \n", c);
printf("The count is %d, length is %d\n", lCount, charCount);
int i;
for(i = 0; i < charCount; i++)
{
char c = a[i];
printf("Char %s = %d \n", &c, value);
}
n = strcmp(char string1[], char string2[], char string3[]);
printf("The first string in the alphabet is: %d \n", n);
return 0;
}

int stringLen(char array[])
{
char count;
int index;
while(array[index] !=0)
{
count++;
index++;
}
return count;
}

int count(char array[], int size)
{
int count;
int i;
for(i = 0; i < size; i++)
{
if(array[i] == 'a')
{
count ++;
}
else if(array[i] == 'A')
{
count ++;
}
}
return count;
}

最佳答案

这不是使用 strcmp 的正确方法。

n = strcmp(char string1[], char string2[], char string3[]);

strcmp 用于字符串的比较。请参阅doc

int result = strcmp (string1,string2)

如果字符串相同,函数将返回0。

关于c - 错误: too few arguments to function 'strcmp' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22573860/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com