如果句子不是 pangram,我正在尝试做一个程序来检测丢失的字母。我在这里搞乱了指针和数组,我完全迷失了。我必须返回一个指向函数 getMissing Letters 的 char 指针,它会将句子作为参数来判断它是否是 pangram。
一个 PAngram 包含所有 26 个字母 az。
#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;
}