题目大致是找出输出的字符串中得A B C D出现的次数,并且按出现次数的从大到小一次输入该字母和出现次数
我得代码是
#include <stdio.h>
void compare4(int s[]);
void charNumprintf(int k[],int x[]);
int main() {
int charNumCount[4]={0};
int charNumcopy[4]={0};
char *str;
scanf("%s",str);
char *p =str;
while (*p !='\n') {
switch (*p) {
case 'A':
charNumCount[0]++;
break;
case 'B':
charNumCount[1]++;
break;
case 'C':
charNumCount[2]++;
case 'D':
charNumCount[3]++;
break;
default:
break;
}
p++;
}
for (int i = 0; i < 4; i++) {
charNumcopy[i] = charNumCount[i];
}
compare4(charNumCount);
charNumprintf(charNumcopy, charNumCount);
return 0;
}
//比较并且交换数值的函数;
void comprae4(int s[])
{
int temp;
for (int i=0; i<4; i++) {
for(int j=1;j<4;j++)
{
if (s[j]>s[i])
{
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
}
void charNumprintf(int k[],int x[])
{
for (int i =0; i < 4;i++) {
for (int j =0; j < 4; j++) {
if(x[i] == k[j])
{
printf("字母%c出现的次数是%d\n",'A'+j,x[i]);
}
}
}
}
可是为什么会报错这个东西:
Undefined symbols for architecture x86_64:
"_compare4", referenced from:
_main in ceshi-d1d433.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
请问这是什么意思啊? |
|