#include
#include
#include
int main(){
int i,j;
char *month[12]={\"January\",\"February\",\"March\",\"April\",\"May\",\"June\",
\"July\",\"August\",\"September\",\"October\",\"November\",\"December\"};
char *cal[12][31]={NULL};
cal[1][1]=\"New Year\";
cal[1][15]=\"Lantern Festival\";
cal[2][14]=\"Valentine\'s Day\";
cal[4][1]=\"April Fools Day \";
cal[5][5]=\"Dragon Boat Festival\";
cal[8][8]=\"Father\'s Day\";
cal[8][15]=\"Mid-Autumn Festival\";
cal[10][10]=\"Double-Tenth Day\";
cal[10][31]=\"Halloween\";
cal[12][25]=\"Christmas\";
for(i=0;i<12;i++)
{
for(j=0;j<31;j++){
if(strcmp(cal[i][j],\"\")!=0)
{
printf(\"%s\\n\",month[i]) ;
printf(\"%d \",j+1);
printf(\"%s\\n\",cal[i][j]);
}
}
}
一個程式作業...
問題出在if判斷式的strcmp
除了for迴圈裏面其他都是老師規定的不能更改
cal[i][j]似乎是個指標不能拿來比較字串??
請大大幫我改看看或是告訴我問題出在哪
麻煩跪求...
2006-07-19 20:42:11 · 1 個解答 · 發問者 陀螺 2 in 電腦與網際網路 ➔ 程式設計
把 strcmp(cal[i][j],"")!=0 改成「cal[i][j]!=NULL」就可以了!
//Power by Microsoft Visual Studio 2005
//可以使用 Dev-C++ 編譯此程式
#include
#include
#include
int main(int argc,char *argv[]){
//=====START=====//
int i,j;
char *month[12]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char *cal[12][31]={NULL};
cal[1][1]="New Year";
cal[1][15]="Lantern Festival";
cal[2][14]="Valentine's Day";
cal[4][1]="April Fools Day ";
cal[5][5]="Dragon Boat Festival";
cal[8][8]="Father's Day";
cal[8][15]="Mid-Autumn Festival";
cal[10][10]="Double-Tenth Day";
cal[10][31]="Halloween";
cal[12][25]="Christmas";
for(i=0;i<12;i++){
for(j=0;j<31;j++){
if(cal[i][j]!=NULL){ //經過修正後!
printf("%s\n",month[i]) ;
printf("%d ",j+1);
printf("%s\n",cal[i][j]);
}
}
}
//=====END=====//
system("PAUSE");
return 0;
}
2006-07-20 01:03:37 · answer #1 · answered by Big_John-tw 7 · 0⤊ 0⤋