當前位置:編程學習大全網 - 網站源碼 - C語言如何讀取壹行數據,以空格分開

C語言如何讀取壹行數據,以空格分開

可以使用strtok函數做分割單詞。

#include<string.h>

voidmain()

{

chars[]="192.168.0.26";

char*delim=".";

char*p;

printf("%s",strtok(s,delim));

while((p=strtok(NULL,delim)))

printf("%s",p);

printf("\n");

}

擴展資料

在C++中strtok的使用

#include<iostream>

#include<cstring>

usingnamespacestd;

intmain()

{

charsentence[]="Thisisasentencewith7tokens";

cout<<"Thestringtobetokenizedis:\n"<<sentence<<"\n\nThetokensare:\n\n";

char*tokenPtr=strtok(sentence,"");

while(tokenPtr!=NULL){

cout<<tokenPtr<<endl;

tokenPtr=strtok(NULL,"");

}

//cout<<"Afterstrtok,sentence="<<tokenPtr<<endl;

return0;

}

  • 上一篇:sap怎麽看代碼行數
  • 下一篇:pubg Sound Integrity插件在哪裏?
  • copyright 2024編程學習大全網