0

Noon や NoOoON などの回文を、回文ではないと言うのではなく、回文であると言うには、コードのどこに toupper() を含める必要がありますか。私はそれを理解できないようです。ありがとう。

#include <stdio.h>
#include <string.h>
#include <ctype.h> 

void reverse(char s[]){ 
    int c, i , j; 
    for (i = 0, j = strlen(s)-1; i < j; i++, j--) { 
        c = s[i]; 
        s[i] = s[j]; 
        s[j] = c; 
    } 
    return; 
} 

int main(){ 
    char a[20];
    char b[20];
    printf("Enter a string:\n");
    gets(a);
    strcpy(b,a); // copies string a to b 
    reverse(a); // reverses string b
    if(strcmp(a, b) == 0) { // compares if the original and reverse strings are the same 
        printf("The string is a Palindrome\n"); 
    } 
    else { 
        printf("The string is not a Palindrome\n"); 
    }    
    return 0; 
}

4

2 に答える 2

1

あなたの場合、_stricmp代わりにstrcmp.

これにアプローチする別の方法は、入力後に文字列を単一のケースに変換することです。例えば

for (char *c = a; *c; c++) *c = toupper(*c);
于 2013-09-23T03:49:04.343 に答える