Law*_*ong 1 c formatting output
我在C中输出格式有一些问题.请参阅下面的图片了解我的输出

我希望我的输出如下
输入字词:KayaK
皮划艇是一个回文.
// palindrome.c
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAXLEN 20
int isPalindrome(char [], int);
int main(void) {
char word[MAXLEN+1];
int size;
printf("Enter word: ");
fgets(word,MAXLEN+1,stdin);
size = strlen(word);
if (isPalindrome(word, size-1)) //size - 1 because strlen includes \0
{
printf("%s is a palindrome.\n",word);
}
else
{
printf("%s is not a palindrome.\n",word);
}
return 0;
}
int isPalindrome(char str[], int size) {
int i;
for (i = 0; i < size; i++)
{
if (tolower(str[i]) != tolower(str[size - i - 1]))
{
return 0;
}
}
return 1;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
137 次 |
| 最近记录: |