作者yzugsr (Bird)
看板Programming
標題Re: [問題] 有誰會C程式語言 (急) 謝謝!!
時間Mon Apr 14 01:26:58 2008
半夜睡不著所以佛心一下 明天還要上班 Orz
※ 引述《Vxprincessx (^^)》之銘言:
: 1. [清除記憶體]Write a function "void bzero(char*p, int n)" to set the n
: contiguous bytes of memory starting from the pointer p to '\0'.
#include <cstring>
void bzero(char*p, int n)
{ memset(p, 0, n); }
: 2. [設定記憶體]Write a function "void bset(char*p, int n, char x)" to set
: n contiguous bytes of memory starting from the pointer p to the value of x.
#include <cstring>
void bset(char*p, int n, char x)
{ memset(p, x, n); }
: 3. [反向字元搜尋]Write a function "int findlast(char *s, char c)" to
: retur
: the index position of the last occurrence of a specified char c within the
: string s, and return -1 if not found, such as findlast("language",'a')
: returns 5.
#include <string>
int findlast(char *s, char c)
{ std::string str(s); return str.rfind(c); }
: 4. [八進位字串轉整數]Write a function "int otoi(char h[])" to convert an
: octal string h to an integer, such as otoi("377") returns 255.
#include <stdio.h>
int otoi(char h[])
{ int i; sscanf(h, "%o", &i); return i; }
: 5. [十六進位字串轉整數]Write a function "int xtoi(char h[])" to convert a
: hexadecimal string h to an integer, such as xtoi("3ff") returns 1023.
#include <stdio.h>
int xtoi(char h[])
{ int i; sscanf(h, "%x", &i); return i; }
: 6. [去兩邊空白]Write a function "void trim(char s[])" to remove the
: rightm
: and leftmost spaces of string s, such as trim(" ab c ") gets "ab c".
#include <boost/algorithm/string.hpp
void trim(char s[])
{ boost::algorithm::trim(s); }
: 希望有好心人幫幫我這可憐的學生
: 這科沒過就要延畢了
: 拜託各位大大幫幫忙
: 我會感激不盡 謝謝
不客氣 你們老師應該會覺得你很厲害 都只要一行就寫完了
半夜寫程式要開燈 不然對視力不好喔
要是因為都用現成的函式被當掉別怪我喔
重修一遍對你可能比較好喔 科科
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.193.35.97
※ 編輯: yzugsr 來自: 123.193.35.97 (04/14 01:27)
推 pthuang:老師:終於有同學達到我的要求了... T__T 118.169.104.1 04/14 02:11
推 liaixyz:代替我朋友謝謝你 XD 125.232.138.19 04/14 08:50
推 zlw:老師應該不知道什麼是boost 122.122.51.120 04/14 08:50
推 nosrep:其實我覺得延畢好..很多畢業出來的程式能力 60.248.204.237 04/14 09:56
→ nosrep:很驚人....@@ 60.248.204.237 04/14 09:57
→ nosrep:而且我不覺得老師需要這個給初學者寫成一行 60.248.204.237 04/14 09:58
推 huggie:C? C++? 218.167.136.86 04/14 09:58
→ nosrep:不過原po很熟c/c++ 60.248.204.237 04/14 09:58
推 Vxprincessx:無論如何 謝謝你!! 125.225.103.156 04/14 15:41
推 vber:拿那些函式去google一下吧,別真的只寫一行 59.104.186.152 04/15 01:26
推 assi:y大真強~!!!不過想跟原PO說... 163.22.18.76 04/15 02:49
→ assi:這些只要有專業一點的程式書,應該都查的到喔~ 163.22.18.76 04/15 02:50
推 archon:sscanf 可以這樣用呀... (筆記) 140.112.42.81 04/15 16:12
→ jameswiki:boost有的c版本沒有吧? 140.116.39.70 04/15 19:39
→ jameswiki:我指上面的string.hpp,學校應會要求用 140.116.39.70 04/15 19:40
→ jameswiki:標準C語法來做,所有C版本都有的function 140.116.39.70 04/15 19:41