#include<stdio.h>
#include<stdlib.h>
void myputs(char *p)//变量的声明形式参数char*p,字符串的特点结尾有'\0'.输出
{
while (*p != '\0')
{
putchar(*p++);
//printf("%c",*p++);
}
putchar('\n');
}
int mygets(char *p)//输入
{
int cnt = 0;
if (p == NULL)
{
printf("内存非法");
return cnt;
}
while (*p = getchar())
{
if (*p == '\n')
{
return;
}
else
{
cnt++;
p++;
}
}
}
int myStrlen(char* str)//初始化
{
int cnt = 0;
while (*str++ != '\0')
{
cnt++;
}
return cnt;
}
void myMemset(char* p, char c, int size)//计数长度
{
while (size)
{
*p++ = c;
size--;
}
}
int main()
{
//char str[128] = {'\0'};
char* str = NULL;
str = (char*)malloc(128);
memset(str, 'a', 128);
str[128] = '\0';
myputs(str);
char* p = "hello";
printf("长度:%d\n", myStrlen(p));
myputs(p);
myputs("请输入你的字符串:\n");
int n = mygets(str);
printf("你输入的字节数是:%d\n",n);
myputs(str);
system("pause");
return 0;
}