Engineering & Technology
大学生・専門学校生・社会人
解決済み
第一個程式執行出來的結果是算出27個位元,而此題正確的解法是第二還有第三張圖片的程式,執行結果是19個位元,請問第一張圖片是哪一個步驟寫錯了呢?為什麼執行結果會和答案不同?請幫幫我,我看了很久都找不出錯誤,謝謝!
.cpp - Dev-C++ 5.11
專案(P) 執行(2) 工具T) AStyle 混密W) 求助(日)
口回贈
TDM-GCC 4.9.2 64-bit Re
**#1.cpp [*] 1.xl#2.cpp hw10_20.c
3 int main()
4日{
5
6
7
8
9自
10
11白
char *ptr[3]={ "Tom", "Lily", "James Lee"};
int total=0, count;
=,;
for(int i=0;i<3;i++)
puts(ptr[i]);
for(int i=0;i<3; i++){
count=0;
=;
while(*(ptr+count)!='\0'){
count++;
;
}
count++;
total=total+count;
}
printf("#%d(MRITT\n", total*sizeof(char));
12
13
14
15
16
17
18
19
system("pause");
return 0;
20
而j 吕歇腳踏
除鐘回覆尋結果 小化
訊息
\\" #
=r\Desktop\新文件2.cpp
\Desktop\新文件2.cpp
er\Desktop\fi+2.cpp
=\Desktop\新文件2.cpp
In function 'int main()':
[Warning] deprecated conversion from string constant to char*' [-Wwrite-strings]
[Warning) deprecated conversion from string constant to 'char* [-Wwrite-strings]
[Warning] deprecated conversion from string constant to 'char*' [-Wwrite-strings]
反白字数:
0
总行数:
21
程案長度: 362
插入模式
完成解析(花了0.016 秒)
devc++\TES\chap10\hw10_20\hw10_20.c - [Executing) - Dev-C++ 5.11
EM 專案(P) 執行工具D AStyle 很密(W) 求助(HD)
区区回目
V dhe
TDM-GCC 4.9.2 64-bit Release
新文件1.cpp 新文件2.cpp hw10 20.c
1 /* hw10 20.0 */
2 #include <stdio.h>
3
#include <stdlib.h>
4 int length(char *);
5 int main(void)
6日 {
7
int i, total=0;
char *ptr[3]={ "Tom", "Lily", "James Lee"}}|
8
9
1白
UN
for(i=0; i<3; i++)
{
puts(ptr[i]);
total+=length(ptr[i]);
}
printf("=187##%d(8LTTI\n", total*sizeof(char));
6
7
system("pause");
return 0;
8
目 詳紀錄/除這回覆尋結果 小化
訊息
esktop\#2.cpp
sktop新文件2.cpp
Esktop\1 #2.cpp
esktop\ #2.com
In function 'int main()':
[Warning) deprecated conversion from string constant to 'char"' [-Wwrite-strings]
[Warning) deprecated conversion from string constant to 'char" - Wwrite-strings)
(S) 檢視V 專案(P) 執行(2) 工具D AStyle 視宮) 求助(H)
魯
回目
v |
TDM-CCC 4.9.2
obals)
)
吉
门新文件1.cpp 新文件2.cpp hw10_20.c
18
return 0;
19 - }
20
21 int length(char *ptr)
22日(
23 int count=0;
24 while(*(ptr+count)!='\0')
(*(+)!'\'
25
count++;
26 count=count+1;
27 return count;
28 - }
29
30 /* output -
31
32 Lily
33 James Lee
34 三個字串共19 個位元組
35
*/
Tom
資源福链紀錄
除嶺區復尋結果長小化
=
訊息
lsers\User\Desktop\新文件2.cpp
users\User\Desktop\新文件2.cpp
Users\User\Desktop\#13+2.cpp
Josers\User Desktop\新文件2.cpp
In function 'int main()':
[Warning] deprecated conversion from string constant to 'char" [-Wwrite-string
[Warning) deprecated conversion from string constant to 'char* (-Wwrite-string
[Warning] deprecated conversion from string constant to 'char [-Wwrite-string
回答
疑問は解決しましたか?
この質問を見ている人は
こちらの質問も見ています😉
程式順利執行了!謝謝你~~~