我的代码存在一些问题。第一:当我尝试编译时,我得到error: too few arguments to function '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;
}
答案 0 :(得分:0)
这不是使用strcmp的正确方法。
n = strcmp(char string1 [],char string2 [],char string3 []);
strcmp
用于比较字符串。见doc
int result = strcmp (string1,string2)
如果字符串相同,则函数将返回0.