[問題] 陣列指標方面的疑惑
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Dev-C++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
無
問題(Question):
這是一個逆向輸出的code 想請教關於陣列指標問題
餵入的資料(Input):
12345
預期的正確結果(Expected Output):
5
4
3
2
1
錯誤結果(Wrong Output):
應用程式錯誤
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <stdio.h>
void reverse(const char* const sptr);
int main(void)
{
char sentence[80];
printf("Enter a line of text:\n");
gets (sentence);
printf("\nThe lineprinted backward is :\n");
reverse(sentence);
return 0;
}
void reverse(const char* const sptr){
if(sptr[0] == '\0'){
return;
}
else{
reverse(&sptr[1]);
printf("%s\n", sptr[0]); /*這個地方有問題*/
}
}
補充說明(Supplement):
原本應該是printf("%s\n, sptr");
它會出現
5
45
345
2345
12345
但我現在想在每一個sptr取第一個 然後顯示出
5
4
3
2
1
但他出現應用程式錯誤的訊息
請教一下各位前輩 小弟我有少考慮什麼嗎
謝謝幫忙
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.230.49
→
11/25 23:48, , 1F
11/25 23:48, 1F
→
11/25 23:50, , 2F
11/25 23:50, 2F
→
11/25 23:50, , 3F
11/25 23:50, 3F
→
11/26 02:46, , 4F
11/26 02:46, 4F
→
11/26 10:44, , 5F
11/26 10:44, 5F