小编Geo*_* Go的帖子

C 将每个字符添加到数组中

对于 C++ - 我可以将每个添加charstring数组中的每个索引:

   string *x=new string[10];
    x[0] += "a";
    x[0] += "b";
    x[0] += "c";
    x[1] += "x";
    x[1] += "y";
    x[1] += "z";
    cout << "x[0]=" << x[0] << endl; // would be "abc"
    cout << "x[1]=" << x[1] << endl; // would be "xyz"
Run Code Online (Sandbox Code Playgroud)

如何在 C 中执行相同的功能?我有一个buff2指向char数组的指针,并试图charbuf. 当我打印出buff2价值时,我不断得到奇怪的价值。

char buf[255];
char *buff2;
int i=0, count=0;
buff2=(char*)malloc(512*sizeof(char));

  while((n = read(fd, buf, sizeof(buf[g]))) > 0){ …
Run Code Online (Sandbox Code Playgroud)

c

2
推荐指数
1
解决办法
115
查看次数

标签 统计

c ×1