char*data和char data[]

籍星汉
2023-12-01

char*data和char data[]的区别要注意:

  • char*data指向字符常量区,其中字符不可修改!
  • char data[]指向栈区,其中字符可以修改!
#include<stdio.h>
#include<string.h>
#pragma warning(disable:4996)

/*
*/
void ReplaceSpace(char* data, const char* xbegin, const char* xend)
{
    char* sbein;
    char* send;
    int ilen, i;
    sbein = strstr(data, xbegin);
    send = strstr(data, xend);
    printf("%c", sbein[0]);
    sbein[0] = 'a';
    printf("%c", sbein[0]);
    printf("%c", *send);
    if ((sbein != NULL) && (send != NULL))
    { 
        send = send + strlen(xend);
        ilen = strlen(sbein) - strlen(send);
        for (i = 0; i < ilen; i++)
        {
            sbein[i] = ' '; 
            printf("newdata:%s\n", data);
        }
    }
}

int main(){
    char data[] = "<name>hello world</name>";
    printf("olddata:%s\n", data);
    ReplaceSpace(data, "<name>", "</name>");
    printf("newdata:%s\n",data);
    system("pause");
}
 类似资料: