问题:编写一个字谜程序,对单词中的字母进行排序,这在搜索字谜时很有用。anagram 接受一个参数,该参数是一个仅包含小写字母的字符串,按字母顺序对字母进行排序,然后打印排序后的字母。您可以使用任何您熟悉的排序算法,但您必须自己编写排序函数。您不得使用库提供的任何排序功能。
用法
$ ./anagram hello
ehllo
$ ./anagram positivity
iiiopsttvy
$ ./anagram abcdef
abcdef
Run Code Online (Sandbox Code Playgroud)
下面的代码是我到目前为止所做的,但我收到错误
将 char * 传递给 unsigned char 的参数会在指向具有不同符号的整数类型的指针之间进行转换
#include <stdio.h>
#include <string.h>
void anagram(unsigned char input[])
{
int count[256] = { 0 };
int i;
for (i = 0; input[i] != '\0'; i++)
{
count[input[i]]++;
}
for (i = 0; i < 256; i++)
{
while (count[i] > 0)
{
printf("%c", i);
count[i]--;
}
}
}
int main(int argc, char* argv[])
{
if(argc > …Run Code Online (Sandbox Code Playgroud)