第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

你好,在C語言中有沒有把字符串拆分為數(shù)組的函數(shù)?如果有,請(qǐng)問是?

你好,在C語言中有沒有把字符串拆分為數(shù)組的函數(shù)?如果有,請(qǐng)問是?

C PHP
浮云間 2022-04-15 18:11:55
張三$|男$|濟(jì)南$|大專學(xué)歷$|如上是一個(gè)字符串, 把上面的字符串按 $| 分成一個(gè)數(shù)組。如:myArray[0] = "張三";myArray[1] = "男";myArray[2] = "濟(jì)南";myArray[3] = "大專學(xué)歷";C語言有沒有提供相關(guān)函數(shù)??? 如果沒有能幫我寫一個(gè)嗎,謝謝。要求能支持中文的。
查看完整描述

3 回答

?
翻閱古今

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊

直接用簡(jiǎn)單的C++


#include <iostream>#include <string>#include <vector>using namespace std; //把字符串s按照字符串c進(jìn)行切分得到vector_v vector<string> split(const string& s, const string& c){    vector<string> v;    int pos1=0,pos2;    while((pos2=s.find(c,pos1))!=-1){        v.push_back(s.substr(pos1, pos2-pos1));        pos1 = pos2 + c.size();      }    if(pos1 != s.length())        v.push_back(s.substr(pos1));    return v; }  int main(){    string input="張三$|男$|濟(jì)南$|大專學(xué)歷$|";    vector<string>  myArray=split(input,"$|");    for(int i=0;i<myArray.size();i++){        cout<<myArray[i]<<endl;    }}/*張三濟(jì)南大專學(xué)歷*/


查看完整回答
反對(duì) 回復(fù) 2022-04-19
?
交互式愛情

TA貢獻(xiàn)1712條經(jīng)驗(yàn) 獲得超3個(gè)贊

用strtok函數(shù)實(shí)現(xiàn)吧。
void split( char **arr, char *str, const char *del)//字符分割函數(shù)的簡(jiǎn)單定義和實(shí)現(xiàn)
{
char *s =NULL;

s=strtok(str,del);
while(s != NULL)
{
*arr++ = s;
s = strtok(NULL,del);
}
}

int main()
{
int i;
char *myArray[4];
char s[] = "張三$|男$|濟(jì)南$|大專學(xué)歷$|";

memset(myArray, 0x0, sizeof(myArray));
split(myArray, s, "$|");

for (i=0; i<4; i++)
{
printf("%s\n", myArray[i]);
}
return 0;
}



查看完整回答
反對(duì) 回復(fù) 2022-04-19
?
慕萊塢森

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊

char str[] = "now $| is the time for all $| good men to come to the $| aid of their country";
char delims[] = "$|";
char *result = NULL;

result = strtok( str, delims );

while( result != NULL )
{
printf( "result is \"%s\"\n", result );
result = strtok( NULL, delims );
}
以上代碼的運(yùn)行結(jié)果是:

result is "now "
result is " is the time for all "
result is " good men to come to the "
result is " aid of their country"

 


查看完整回答
反對(duì) 回復(fù) 2022-04-19
  • 3 回答
  • 0 關(guān)注
  • 185 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)