“freopen_s”不能将参数 1 从“char (*)[100]”转换为“FILE **

#include "stdafx.h"

#include <string.h>

#include <stdio.h>
 
void str_replace(char * cp, int n, char * str)
{
	int lenofstr;
	int i;
	char * tmp;
	lenofstr = strlen(str); 
	//str3比str2短,往前移动 
	if(lenofstr < n)  
	{
		tmp = cp+n;
		while(*tmp)
		{
			*(tmp-(n-lenofstr)) = *tmp; //n-lenofstr是移动的距离 
			tmp++;
		}
		*(tmp-(n-lenofstr)) = *tmp; //move '\0'	
	}
	else
	        //str3比str2长,往后移动
		if(lenofstr > n)
		{
			tmp = cp;
			while(*tmp) tmp++;
			while(tmp>=cp+n)
			{
				*(tmp+(lenofstr-n)) = *tmp;
				tmp--;
			}   
		}
	strncpy_s(cp,sizeof(cp),str,lenofstr);
}

int main()
{

   	char str1[1024]; 
	char str2[100],str3[100];	 
   	int i,len,count=0;
   	char c;
   	char *p;  	
   	
   	printf("\n请输入要查找的字符串和用于替换的字符串(中间用空格隔开): ");
   	scanf_s("%s",str2);
        scanf_s("%s",str3);
        //read string from news.txt
	freopen_s( &str2,"news.txt","r",stdin);
	i=0;
	c = getchar();
	while(c!=EOF)
	{
		str1[i] = c;
		i++;
		c = getchar();
	}
	str1[i]	= '\0';
	
	//开始查找字符串str2 
   	p = strstr(str1,str2);
   	while(p)
	{
		count++;
		//每找到一个str2,就用str3来替换 
		str_replace(p,strlen(str2),str3);
		p = p+strlen(str3);
		p = strstr(p,str2);
	}   	
   	printf("\ncount = %d\n",count); 
	printf("Result = %s\n",str1);        
}

 

  error C2664: “freopen_s”: 不能将参数 1 从“char (*)[100]”转换为“FILE **”

 第52行,怎么修改代码解决这个问题。

 

 

你需要这样写吧:

    FILE *file;

    freopen_s(&file, str2, "news.txt", stdin);

    freopen_s(&file, "news.txt", "r", stdin);

FILE *stream1; 
freopen_s(&stream1, "in.txt", "r", stdin); 

这个函数第一个参数要求是FILE*

你这段代码和文件有啥关系啊,没看出来

 

把&str1,改成FILE*bian kianh