Skip navigation.

滩头一粒沙,世间一刹那

人生何其短!

在GCC下编译通过但运行不正确是不是我的GCC有问题呀!

这个程序在我的TC下与G++下编译后运行结果正确,可是用GCC编译运行了就是不对!不解!!!!

/*这个程序在我的TC下与G++下编译后运行结果正确,可是用GCC编译运行了就是不对!不解!!!!:worried: :eyes: :frown:
*/
/*
1.将以下字符串按字母先后顺序排列并输出:
shanghai,gangdong,anhui,henan,zhejiang,jiangsu,shandong
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
main ()
{
char str[7][10]={{"shanghai"},{"gangdong"},{"anhui"},{"henan"},{"zhejiang"},{"jiangsu"},{"shandong"}};
char temp[10]={'\0'};
int i,j,k,Dif;
for (i=0;i<7;i++)
{
for (j=0;j<7-i;j++)
{
Dif=strcmp (str[j],str[j+1]);
if (Dif>0)
{
strcpy(temp,str[j]);
strcpy(str[j],str[j+1]);
strcpy(str[j+1],temp);
}
}
}
for (k=0;k<7;k++)
printf ("%s ",str[k]);
printf ("\n");

}

ANSI C 下库函数中strcmp函数的实现拷贝数组函数的一个变体

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies