我可以帮您进行翻译。以下是需要翻译的内容:
它通过了那些bb,但也通过了先前的AA..即使数组只有两个位置,当我在其中使用strtol时,它会给我一些大值而不是我正在寻找的187..如何摆脱它?或者如何使它以其他方式工作?任何建议都将不胜感激。
我有一个字符串AAbbCC,我需要做的是将前两个字符复制并添加到一个数组中,然后将中间两个字符复制并添加到另一个数组中,最后将最后两个字符复制并添加到一个数组中。
这是我的做法:
char color1[2];
char color2[2];
char color3[2];
strncpy(color1, string, 2); // I take the first two characters and put them into color1
// now I truncate the string to remove those AA values:
string = strtok(string, &color1[1]);
// and when using the same code again the result in color2 is bbAA:
strncpy(color2, string, 2);
它通过了那些bb,但也通过了先前的AA..即使数组只有两个位置,当我在其中使用strtol时,它会给我一些大值而不是我正在寻找的187..如何摆脱它?或者如何使它以其他方式工作?任何建议都将不胜感激。
strncpy(color2, string+2, 2); color2[2] = '\0'
等等? - Anthalesstrtoul
而不是先将其切成几块呢? - Mr Lister