[問題] 如何回傳字串指標中的某個記憶體位址?

看板C_and_CPP (C/C++)作者時間16年前 (2009/03/23 00:20), 編輯推噓4(408)
留言12則, 3人參與, 最新討論串1/2 (看更多)
http://rafb.net/p/FXzfKy46.html 這是C++ primer plus 第八章的練習題第六題 題目的一部分是要求要傳入一個char指標陣列給函式, 然後要回傳其中最長字串的記憶體位址。 我卡在回傳記憶體位址的地方,不知道該怎麼修改才對。 請板友們幫我看看,謝謝! -------------------------------------- 我把部分的題目貼上來好了 The program also should include a specialization that takes an array of pointers-to-char as an argument and the number of pointers as a second argument and which returns the address of the longest string. If there are more than one string having the longest length, the function returns the address of the first one tied for longest. Test the specialization with an array of 5 string pointers. 我想問的就是上面這件事情.. P.S. C++真不好學啊...雖然學過C.. -- 我以為遠方 會有新的風景 卻在每一個異地 流浪回望著記憶 "For the way I live" by Tizzy Bac -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.194.100.216

03/23 00:25, , 1F
其實我想說的是回傳記憶體位址似乎不是 C++ 才有的東西..
03/23 00:25, 1F

03/23 00:27, , 2F
不過理論上你應該要用 template 寫才對吧?
03/23 00:27, 2F

03/23 00:28, , 3F
15我知道不是C++才有的東西..不過我真的不會T_T
03/23 00:28, 3F

03/23 00:28, , 4F
我是不會取那個記憶體位址啦..
03/23 00:28, 4F

03/23 00:28, , 5F
不知道該怎麼做Q_Q
03/23 00:28, 5F

03/23 00:33, , 6F
你的程式想做什麼我看不太懂, 問題是出在跑不完嗎
03/23 00:33, 6F

03/23 00:35, , 7F
建議你講解一下 你各個functyion 在做什麼 一頭霧水
03/23 00:35, 7F
※ 編輯: zptdaniel 來自: 123.194.100.216 (03/23 00:37)

03/23 00:38, , 8F
主要想問int* maxn(char *,int n=5) 這個函式
03/23 00:38, 8F

03/23 00:38, , 9F
這個函式要做的事情就是上面那段英文題目
03/23 00:38, 9F

03/23 00:45, , 10F
為啥要用 int* 呢? 而且思考一下 array of pointers-to-c
03/23 00:45, 10F

03/23 00:50, , 11F
har 的意義是什麼
03/23 00:50, 11F

03/23 11:00, , 12F
謝謝!我寫出來了^^
03/23 11:00, 12F
文章代碼(AID): #19ncLd0F (C_and_CPP)
文章代碼(AID): #19ncLd0F (C_and_CPP)