概述
字符串分配内存的三种方式:堆上、栈上、全局常量区
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct CString
{
char *p;
int reallength;
};
typedef struct CString mystring;
void init(mystring *string);
void initwithlength(mystring *string, int length);
void initwithstring(mystring *string, char *copystring);
void printfstring(mystring *string);
void backaddchar(mystring *string, char ch);
void backaddstring(mystring *string, char *str);
void run(mystring *string);
char * findfirstchar(mystring *string, char ch);
char * findfirststring(mystring *string, const char *str);
int deletefirstchar(mystring *string, char ch);
int deletefirststring(mystring *string, const char *str);
void addchar(mystring *string, char ch, char *pos);
void addstring(mystring *string, char *str, char *pos);
void changefirstchar(mystring *string, const char oldchar, const char newchar);
void changefirststring(mystring *string, char * const oldstring, char * const newstring);
#include"字符串.h"
int mystrlen(char *p)
{
if (p == NULL)
{
return -1;
}
int length = 0;
while (*p != '