0
我试图做一个程序来检测缺少的字母,如果一个句子不是pangram。我在这里搞乱了指针和数组,而我完全迷失了。 我不得不返回一个字符指针到函数getMissing Letters,并且它接受作为参数的句子来检查它是否为a pangram。数组指针和返回类型
一个PAngram包含所有26个字母a-z。
#include <stdio.h>
include <stdlib.h>
char * getMissingLetters(const char *sentence)
{
char ch, allchars[26] = {0};
char * missing[26]={0};
int total = 0,i;
while ((ch = *sentence++)) {
int index;
if('A'<=ch&&ch<='Z')
index = ch-'A';
else if('a'<=ch&&ch<='z')
index = ch-'a';
else
continue;
total += !allchars[index];
allchars[index] = 1;
}
for(i=0;i<26;i++)
{
if(allchars[i]==0)
missing[i]=(char)(i+97);
printf("missing[i]=%c\n",missing[i]);
}
return missing;
}
int main()
{
int i;
const char *tests[] = {
"A slow yellow fox crawls under the proactive dog",
"The quick brown fox jumps over the lazy dog.",
"Lions, and tigers, and bears, oh my!"
};
char * missing[26];
for (i = 0; i < 3; i++){
missing = isPangram(tests[i]);
}
return 0;
}
您能更具体地了解您遇到的问题吗?另外,我建议你阅读[c-faq.com](http://c-faq.com/)上的[指针部分](http://c-faq.com/ptrs/index.html),并可能还有其他与指针相关的部分。 – ughoavgfhw 2013-02-25 23:58:36