简单C++输写 求错

来源:百度知道 编辑:UC知道 时间:2024/06/09 11:00:43
#include<stdio.h>
#include< math.h>
#define NULL 0
main()
{ int i=0;
FILE *fp;
char str[100];
if((fp=fopen("test","w"))==NULL)
{
printf("\n can not open File\n");
exit(0); }
printf("enter the string");
getchar();
gets(str);
while(str[i]!='!')
{
if(str[i]>='a'&&str[i]<='z')
str[i]-=32;
i++;
}
fputs(str,i+1,fp);
fclose(fp);
fp=fopen("test","r");
fgets(str,i+1,fp);
fclose(fp);
}
我这样写 会有错?fgets(str,i+1,fp); fputs(str,i+1,fp); 特别这个两个

#include <stdlib.h> // exit(0); 在这个库里

char * fputs(char *, FILE *);//第一个参数是字符指针类型,第二参数是文件指针。

修改这两处你的程序就没问题了。

#include<stdio.h>
#include <stdlib.h> /*.................*/
#include<math.h>

#define NULL 0
void main()
{
int i=0;
FILE *fp;
char str[100];
if((fp=fopen("test","w"))==NULL)
{
printf("\n can not open File\n");
exit(0);
}
printf("enter the string");
getchar();
gets(str);
while(str[i]!='!')
{
if(str[i]>='a'&&str[i]<='z')
str[i]-=32;
i++;
}
fputs(str,fp); /*.................*/
fclose(fp);
fp=fopen("test","r");
fgets(str,i+1,fp);
fclose(fp);
printf("%s",str); /*.................*/
}

fputs只能传入两个参数的,你程序里传入3个了