这个程序虽然给出错误提示,我依然不会改,请帮忙!
下面这个程序,是想把文件str2的内容追加到str1中去,str3作为中间传送的字符串数组。count来统计追加的文件的个数。用setvbuf创建一个1024字节的缓冲区。
运行时错误提示为'fread' : cannot convert parameter 4 from 'char [1000]' to 'struct _iobuf *'和'fwrite' : cannot convert parameter 4 from 'char [1000]' to 'struct _iobuf *'。请问,怎样改动?
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define SIZE 1000
int main(void)
{
char str1[SIZE];
char str2[SIZE];
char str3[10];
FILE *in, *out;
int count = 0;
printf("Please input the source file's name:");
gets(str1);
in = fopen(str1, "a+");
if((setvbuf(in, NULL, _IOFBF, 1024)) != 0)
{
fprintf(stderr, "Can not create buffer of &s", str1);
exit(2);
}
printf("Please input the destination file's name:");
while(gets(str2) != NULL && str2[0] != '\0')
{
if(strcmp(str1, str2) == 0)
{
fputs("Can not copy itself.\n", stderr);
exit(3);
}
else
{
if((setvbuf(out, NULL, _IOFBF, 1024)) != 0)
{
fputs("Failing in creating the buffer for the file.\n", stderr);
continue;
}
out = fopen(str2, "r");
if(out == NULL)
{
fputs("Failing in opening the file.\n", stderr);
}
fread(str3, sizeof(char), 10, str2);
fwrite(str3, sizeof(char), 10, str1);
}
count++;
}
fclose(in);
fclose(out);
return 0;
}
#include "stdio.h"
#include "string.h"
#include "stdlib.h"
#define SIZE 1000
int main(void)
{
char str1[SIZE];
char str2[SIZE];
char str3[10];
FILE *in, *out;
int count = 0;
printf("Please input the source file's name:");
fgets(str1, SIZE, stdin);
in = fopen(str1, "a+");
if((setvbuf(in, NULL, _IOFBF, 1024)) != 0)
{
fprintf(stderr, "Can not create buffer of &s", str1);
exit(2);
}
printf("Please input the destination file's name:");
while(fgets(str2, SIZE, stdin) != NULL && str2[0] != '\0')
{
if(strcmp(str1, str2) == 0)
{
fputs("Can not copy itself.\n", stderr);
exit(3);
}
else
{
if((setvbuf(out, NULL, _IOFBF, 1024)) != 0)
{
fputs("Failing in creating the buffer for the file.\n", stderr);
continue;
}
out = fopen(str2, "r");
if(out == NULL)
{
fputs("Failing in opening the file.\n", stderr);
}
fread(str3, sizeof(char), 10, in);
fwrite(str3, sizeof(char), 10, out);
}
count++;
}
fclose(in);
fclose(out);
return 0;
}