如何将这些字符转换为小写?使用 tolower() 不起作用。
我有一个这样的数组:
static char clef[][7] =
{
['A'] = "X",
['B'] = "Y",
['C'] = "Z",
['D'] = "A",
['E'] = "B",
['F'] = "C",
['G'] = "D",
['H'] = "E",
['I'] = "F",
['J'] = "G",
['K'] = "H",
['L'] = "I",
['M'] = "J",
['N'] = "K",
['O'] = "L",
['P'] = "M",
['Q'] = "N",
['R'] = "O",
['S'] = "P",
['T'] = "Q",
['U'] = "R",
['V'] = "S",
['W'] = "T",
['X'] = "U",
['Y'] = "V",
['Z'] = "W"
};
此代码旨在根据上述键数组的变化替换文本中的字母。新文本全部大写。我想让它们小写,除非在“。”之后的情况下。标记一个新句子的开始。
static void crack(FILE *fp, const char *buffer, const char *pad1, const char *pad2, int shift_index)
{
int c;
char d;
const char *pad = pad1;
int col = 0;
idx = shift_index - 4;
for (int i = 0; (c = buffer[i]) != '\0'; i++)
{
if (col == 0)
{
fputs(pad, fp);
col += strlen(pad);
pad = pad2;
}
col++;
c = toupper(c);
printf("C :: %d", c);
if (c < MAX_CLEF && clef[c][0] != '\0')
{
/*fputs(clef[c - idx], fp);
printf("Value : %s", clef[c-idx]);*/
if (buffer[i - 1] == '.') {
fputs(clef[c - idx], fp);
}
else {
fputs(tolower(clef[c-idx]), fp);
}
col += strlen(clef[c - idx]);
}
else
{
putc(c, fp);
col++;
printf("C :: right here %d", c);
}
if (col > 72)
{
putc('\n', fp);
col = 0;
}
}
}
但是,我在编译时收到了一些警告:
incompatible pointer to integer conversion passing 'char [7]' to parameter
of type 'int' [-Wint-conversion]
fputs(tolower(clef[c-idx]), fp);
和
incompatible integer to pointer conversion passing 'int' to parameter of
type 'const char *' [-Wint-conversion]
fputs(tolower(clef[c-idx]), fp);