C语言的排序问题

qq1157471424 2011-02-09 04:31:21
// sort.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"

//对一个数组的前苦干个数据进行排序
void Sort(int* pData,int iCount)
{
int iTemp;
for(int i= 1; i < iCount;i++)
{
for(int j = iCount-1 ;j >= i;j--)
{
printf ("处理第%d个数据和第%d个数据\n",j,j-1);
if(pData[j] < pData[j-1])
{
iTemp = pData[j-1];
pData[j-1] = pData[j];
pData[j] = iTemp;
}
}
printf ("处理完一轮\n\n");
}
}

//输出一个数组的前苦干个数据
void Print(int* pData,int iCount)
{
for(int i = 0 ; i < iCount ; i++ )
printf("%d ",pData[i]);
}

int main(int argc, char* argv[])
{
int data[] = {16,90,70,18,6,5,4};
//将原始数据输出
printf("原始数据为:\n");
Print(data,7);
printf("\n");

Sort(data,7);

//将排序后的数据输出
printf("排序后的数据为:\n");
Print(data,7);
printf("\n");
return 0;
}
小弟刚开始学C语言两天,看到C语言视频教程里面的排序,我照里面的内容输入为什么会提示错误?
-------------------Configuration: sort - Win32 Debug--------------------
Compiling...
sort.cpp
D:\a\MyProjects\sort\sort.cpp(15) : error C2018: unknown character '0xa3'
D:\a\MyProjects\sort\sort.cpp(15) : error C2018: unknown character '0xac'
D:\a\MyProjects\sort\sort.cpp(15) : error C2146: syntax error : missing ')' before identifier 'j'
D:\a\MyProjects\sort\sort.cpp(15) : error C2059: syntax error : ')'
Error executing cl.exe.

sort.exe - 4 error(s), 0 warning(s)
我看了字母大小和分隔,都一模一样,搞不清楚错在哪,请高手帮忙下
...全文
183 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq1157471424 2011-02-09
  • 打赏
  • 举报
回复
确实逗号错误·- -!切换来切换去的,就乱了·
yuanboailanqiu 2011-02-09
  • 打赏
  • 举报
回复
同意 逗号感觉不对
masmaster 2011-02-09
  • 打赏
  • 举报
回复
源程序文件编码必须是ascii格式,文中似乎有全角字符,比如:
printf ("处理第%d个数据和第%d个数据\n",j,j-1);
其中一个逗号就是全角的,编译的时候, 当然通不过啦。
梁诚斌 2011-02-09
  • 打赏
  • 举报
回复
Sort函数里的for(int j = iCount-1 ;j >= i;j--)
{
printf ("处理第%d个数据和第%d个数据\n",j,j-1);
printf函数里的第一个逗号格式不对,要英文格式下的逗号
S_aladdin 2011-02-09
  • 打赏
  • 举报
回复

printf ("处理第%d个数据和第%d个数据\n",j,j-1);


这句的第一个逗号明显有问题,再好好看看其它的字符吧

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧