[問題] reverse串列問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Dev-C
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
餵入的資料(Input):
一串數字
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <stdio.h>
#include <stdlib.h>
void main(void){
char *origin;
printf("please:");
scanf(origin);
strlen(origin);
reverse(origin);
printf("The output: %d",origin);
system("pause");
return 0;
}
void reverse(char* input){
int length = strlen(input);
int first=0;
int last=length-1;
while(first<last){
char temp;
temp=input[first];
input[first]=input[last];
input[last]=temp;
first++;
last--;
}
}
補充說明(Supplement):
編譯時會報錯
[Error] '::main' must return 'int'
[Error] 'strlen' was not declared in this scope
[Error] 'reverse' was not declared in this scope
覺得我的定義函數沒有任何違法問題呀
但是還是無法順利編譯過去,另外請益一下,我的程式呼叫邏輯算正確嗎??
怕到時候跑出不一樣的結果!!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.39.12.135
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1396419088.A.FFF.html
→
04/02 16:08, , 1F
04/02 16:08, 1F
→
04/02 16:09, , 2F
04/02 16:09, 2F
→
04/02 16:09, , 3F
04/02 16:09, 3F
想請問一下副程式的部分邏輯是對的嗎??
因為我是改寫課本上的範例用迴圈方式
推
04/02 16:38, , 4F
04/02 16:38, 4F
→
04/02 16:38, , 5F
04/02 16:38, 5F
推
04/02 16:40, , 6F
04/02 16:40, 6F
※ 編輯: oklp1415 (114.27.124.145), 04/03/2014 15:51:37