#include
#include
int main()
{
char movie[5][100]={{\"The Davinci Code\"},{\"The Hill Have eyes\"},{\"Mission Impossible 3\"},{\"Silent Hill\"},{\"Ice age 2\"}};
char *p;
//movie[0]= \"The Davinci Code\";
//movie[1]= \"The Hill Have eyes\";
//movie[2]= \"Mission Impossible 3\";
//movie[3]= \"Silent Hill\";
//movie[4]= \"Ice age 2\";
int c=0;
p=movie[5][100];
for (int k=0; k<5; k++)
{
for(int i=0; i
if ( *p== \'c\'||*p==\'C\' )
{
cout<<\"c\"<
}
}
}
cout<<\"c總計出現有\"<
}
2006-05-19 17:31:04 · 4 個解答 · 發問者 ? 1 in 電腦與網際網路 ➔ 程式設計
char *p; // <--- 你要的是char,不是 char*,請改為下面的樣子
char p;
p=movie[5][100]; // <--- 這行沒有意義,請移除
p = movie[k][i]; // 這是另外加上的
if ( *p== 'c'||*p=='C' ) // 修改這行成為下面那行,並在這行上方加入上面那行
if ( p== 'c'||p=='C' )
最後應該像這樣:
#include
#include
int main()
{
char movie[5][100]={"The Davinci Code","The Hill Have eyes","Mission Impossible 3","Silent Hill","Ice age 2"};
char p;
//movie[0]= "The Davinci Code";
//movie[1]= "The Hill Have eyes";
//movie[2]= "Mission Impossible 3";
//movie[3]= "Silent Hill";
//movie[4]= "Ice age 2";
int c=0;
p=movie[5][100];
for (int k=0; k<5; k++)
{
for(int i=0; i
p = movie[k][i];
if ( p== 'c'||p=='C' )
{
cout<<"c"<
}
}
}
cout<<"c總計出現有"<
}
2006-05-19 17:52:44 · answer #1 · answered by Bobo 3 · 0⤊ 0⤋
當我們宣告char movie[5][100];時系統並不會分配movie[5][100]這個值,最多只有到movie[4][99]
2006-05-24 19:23:28 · answer #2 · answered by ? 4 · 0⤊ 0⤋
二個都很厲害 不知道要選誰 所以交給投票了
2006-05-20 03:15:05 · answer #3 · answered by ? 1 · 0⤊ 0⤋
因為沒有提到說哪邊是規定不允許修改的,我假設char movie[5][100]和char *p的宣告不能改的話:
int main()
{
char movie[5][100]={{"The Davinci Code"},{"The Hill Have eyes"},{"Mission Impossible 3"},{"Silent Hill"},{"Ice age 2"}};
char *p;
//movie[0]= "The Davinci Code";
//movie[1]= "The Hill Have eyes";
//movie[2]= "Mission Impossible 3";
//movie[3]= "Silent Hill";
//movie[4]= "Ice age 2";
int c=0;
p=(char *)movie;
for (int k=0; k<5; k++)
{
for(int i=0; i
// if (*(*(movie+k)+i)=='c' || *(*(movie+k)+i)=='C') ←假設沒規定要用宣告的p直接用movie的話可以這樣寫
if (*(p+k*100+i)=='c' || *(p+k*100+i)=='C')
{
cout<<"c"<
}
}
}
cout<<"c總計出現有"<
}
2006-05-20 02:13:23 · answer #4 · answered by chan 5 · 0⤊ 0⤋