字符串处理

xiaoxiao2021-02-28  38

#include <stdio.h> #include <string.h> char res[5000000]; int main() {     int n;     scanf("%d", &n);     int len = 0;     for (int i = 1; i <= n; ++i) {         strcat( /*在这里填写必要的代码*/ , res);         res[len] = 'A' + i - 1;         len = strlen(res);     }     printf("%s\n", res);     return 0; }

答案是:res+len+1。

   res+len+1是扩充了字符串,然后把另一个res加到这个数组的末尾,中间留了一个\0,然后把\0替换掉。 比如原字符串是'A',res+len+1后变成'A\0\0',strcat后变为'A\0A',然后把\0替换为B。

转载请注明原文地址: https://www.6miu.com/read-1950179.html

最新回复(0)