void my_fputc(char *path)
{
if (path == NULL)
{
return;
}
FILE* fp;
fp = fopen(path, "w+");
if (fp == NULL)
{
perror("fopen");
system("pause");
return;
}
char buf[] = "this is test";
char tmp1[20] = { 0 };
char tmp2[20] = "lyyyw";
int i = 0;
int n = strlen(buf);
for (i = 0; i < n; i++)
{
int ret = fputc(buf[i],fp);
sprintf(tmp1,"%c",ret);
strcpy(tmp2[i],tmp1[0]);
//printf("%c", ret);
}
if (fp != NULL)
{
fclose(fp);
fp = NULL;
}
}
void my_fgetc(char* path)
{
FILE* fp;
fp = fopen(path, "r+");
char ch;
if (fp == NULL)
{
perror("fopen");
system("pause");
return;
}
//while ((ch = fgetc(fp)) != EOF)
while(!feof(fp))
{
ch = fgetc(fp);
printf("%c",ch);
}
if (fp != NULL)
{
fclose(fp);
fp = NULL;
}
}
int main(void)
{
my_fputc("../test.txt");
//my_fgetc("../test.txt");
printf("\n");
system("pause");
}
为什么这种情况下strcpy会出现错误,两个变量都是有内存的