代码如下,
#include<stdio.h>
#define Wordnumber 100
#define Maxwords 10
int main()
{
char words[Maxwords][Wordnumber];
int countwords(char words[Maxwords][Wordnumber], int i);
int word_counter[Maxwords];
int is,temp = 0;
int k = 0;
int j = 0;
printf("Please enter the word:\n");
for (is=0; is<10; is++)
{
gets_s(words[is]);
if (words[is] == "exit")
{
break;
}
}
//进行单词数叠加(此处报错
for (j = 0; j<10; j++)
{
word_counter[j] = countwords(words[j], j);
k = k + word_counter[j];
}
//排序
for (is=0; is<10; is++)
{
for (j; j<10 - is; j++)
{
if (word_counter[j]>word_counter[j + 1])
{
temp = word_counter[j + 1];
word_counter[j + 1] = word_counter[j];
word_counter[j] = temp;
}
}
}
k = word_counter[9] * 11 - k;
printf("%d", k);
return 0;
}
int countwords(char words[Maxwords][Wordnumber], int i)
{
int roundtime = 0;
static int blank = 0;
int blankspace = 0;
while (roundtime != 0)
{
for (blank; blank<Wordnumber; blank++)
{
if (words[i][blank] == ' ')
{
blankspace++;
}
if (words[i][blank] == NULL)
{
roundtime++;
break;
}
}
}
return blankspace + 1;
}
// error C2664: “int countwords(char [][100],int)”: 无法将参数 1 从“char [100]”转换为“char [][100]”
c语言初学者,ide为VS2013,无法实现数单词的功能。
错误不知一个
1. int countwords(char words[Maxwords][Wordnumber], int i) 是不能这样定义的,你无法获得maxwords/wordnumber。
2. countwords(words[j], j); 指针级数不对。
买本书看看吧。