【发布时间】:2021-02-03 22:20:30
【问题描述】:
该代码旨在检查两个单词是否是字谜。我希望它区分大小写,但是使用 strlwr 会产生错误。如何更改它以使其适用于小写和大写?目前它只适用于其中一个。
#include <stdio.h>
#include <string.h>
void sort(char str[]);
int main(void){
char FirstWord[10];
char SecondWord[10];
printf("Enter the first word \n");
scanf("%s", FirstWord);
printf("Enter the second word \n");
scanf("%s", SecondWord);
sort(FirstWord);
sort(SecondWord);
if(strcmp(FirstWord, SecondWord)==0)
printf("First word and second word are the same \n");
else
printf("Words are different \n");
}
void sort(char str[]){
int i,j,swapper, ArrayLength = strlen(str);
for(i=0; i<ArrayLength; i++)
for(j=0; j<ArrayLength; j++)
if (str[i] < str[j]){
swapper=str[i];
str[i]=str[j];
str[j]=swapper;
}
}
【问题讨论】:
-
不要说“创建错误”,而是请显示您收到的准确错误文本。
标签: c