c语言中拆分的函数 c语言拆分组合形成新数( 二 )


}
int sc(){
int i,j;
int br[3][3];
for(i=0;i3;i++)
for(j=0;j3;j++)
br[i][j]=arr[j][i];//转置后的数组暂放在数组br中
for(i=0;i3;i++)
for(j=0;j3;j++)
arr[i][j]=br[i][j];//将转置后的数组赋值给arr;
return 0;
}
void printfarr(int arr[3][3]){//输出数组
int i,j;
for(i=0;i3;i++)
{
for(j=0;j3;j++)
printf("%d ",arr[i][j]);
printf("\n");
}
}
结果和上边一样 。
C语言中字符切割函数split的实现#include stdio.h
#include string.h
// 将str字符以spl分割,存于dst中 , 并返回子字符串数量
int split(char dst[][80], char* str, const char* spl)
{
int n = 0;
char *result = NULL;
result = strtok(str, spl);
while( result != NULL )
{
strcpy(dst[n++], result);
result = strtok(NULL, spl);
}
return n;
}
int main()
{
char str[] = "what is you name?";
char dst[10][80];
int cnt = split(dst, str, " ");
for (int i = 0; icnt; i++)
puts(dst[i]);
return 0;
}
C语言有没有把字符串拆分为数组的函数?直接用简单的C++
#include iostream
#include string
#include vector
using namespace std;
//把字符串s按照字符串c进行切分得到vector_v
vectorstring split(const string s, const string c){
vectorstring 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="张三$|男$|济南$|大专学历$|";
vectorstringmyArray=split(input,"$|");
for(int i=0;imyArray.size();i++){
coutmyArray[i]endl;
}
}
/*
张三

济南
大专学历
*/
关于c语言中拆分的函数和c语言拆分组合形成新数的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

推荐阅读