【发布时间】:2015-07-19 06:46:34
【问题描述】:
嘿,伙计们实际上是 c 编程的新手。我有一个 char 数组,并试图保持元素有序。我已经成功完成了,但是当我打印数组的元素时,我的代码中会出现一个额外的字符 ÿ。
我的代码
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
char values[4] = "mmfa";
int cmpfunc (const void * a, const void * b)
{
return(*(char*)a - *(char*)b);
}
int main()
{
int n;
qsort(values, 5, sizeof(char), cmpfunc);
printf("\nAfter sorting the list is: \n");
for( n = 0 ; n < 5; n++ )
{
printf("%c ", values[n]);
}
return(0);
}
当我打印这个我得到结果ÿ a f m m.我需要删除ÿ..我已经尝试通过使用\ 转义aray 但它没有成功。那么我将如何删除结果中的ascii code。
感谢您的帮助
【问题讨论】:
-
如果只有 4 个值,请不要对 5 个值进行排序。
标签: c