我的代码有一些问题。首先:当我尝试编译时,得到error: too few arguments to function 'strcmp'
。我四处张望,进行了多项更改,但仍然无法正常工作。第二:当我的代码确实编译时(如果删除了strcmp部分),它将无法正确完成count函数。谁能帮忙吗?谢谢!
#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 - 错误:函数'strcmp'的参数太少,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22573860/