类型为“char(*)[16]”的参数与“const char *”类型的参数不兼容 [英] Argument of type "char (*)[16]" is incompatible with parameter of type "const char *"
问题描述
你好,
我正在使用visual studio 2015执行交流程序
i我试图从文件中读取数据,但我收到错误:'文件* fopen(const char *,const char *)':不能将参数1从'char(*)[16]'转换为'const char *'
以及
类型char(*)[16]的参数与const char *类型的参数不兼容
有人可以帮我解决这个问题
感谢你,
spanika kamuni
我尝试过:
hello,
I am using visual studio 2015 to perform a c program
i am trying to read the data from a file, but i am getting error:'FILE *fopen(const char *,const char *)': cannot convert argument 1 from 'char (*)[16]' to 'const char *'
and also
argument of type "char (*)[16]" is incompatible with parameter of type "const char *"
can someone please help me to fix this
Thanking you,
spanika kamuni
What I have tried:
include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include <iostream>
#include <string>
#include "stdafx.h"
#define MAXNAME 16
void main(int argc, char *argv[])
{
int c, i, j, f;
char lib[MAXNAME] = "lib\0 ";
FILE *in, *out;
char name[MAXNAME];
/* open input file */
i = 0;
while ((name[i] = *argv[1]) != '\0') {
i++;
argv[1]++;
}
if ((in = fopen(&name, "r")) == NULL) {
printf("Can't open file\n");
goto end;
}
/* open output file. Same name as input but with .lib extension */
while (name[i] != '.') i--;
j = 0;
i++;
while (MAXNAME >= (i + j)) {
name[i + j] = lib[j];
j++;
}
if ((out = fopen(&name, "w")) == NULL) {
printf("Can't open file\n");
goto end;
}
}
推荐答案
您的变量name
是一个数组,因此您不需要在其前面使用addressof运算符(&)。它应该是:
Your variablename
is an array, so you do not need the addressof operator (&) in front of it. It should be:
if ((in = fopen(name, "r")) == NULL) {
和输出文件相同。
and the same for the output file.
这篇关于类型为“char(*)[16]”的参数与“const char *”类型的参数不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!