Reputation: 99
This is part of my code. My program reads a .txt and analyzes the instructions written in the text to perform the actions.
char *insertar(char line[1024],int num)
{
int i=9;
int pos=0;
char c;
while(i<strlen(line))
{
c=line[i];
switch(pos){
case 0:
if((c[0]!=',')||(c[0]!=')'))
{
strcat(reg[num].codigo,c);
}
else{
pos++;
}
break;
case 1:
if((c[0]!=',')||(c[0]!=')'))
{
strcat(reg[num].placa,c);
}
else{
pos++;
}
break;
case 2:
if((c[0]!=',')||(c[0]!=')'))
{
strcat(reg[num].year,c);
}
else{
pos++;
}
break;
case 3:
if((c[0]!=',')||(c[0]!=')'))
{
strcat(reg[num].tipo,c);
}
else{
pos++;
}
break;
case 4:
if((c[0]!=',')||(c[0]!=')'))
{
strcat(reg[num].marca,c);
}
else{
pos++;
}
break;
default:
reg[num].estado=1;
return 0;
break;
}
i++:
}
fwrite();
}
The problem is that in every line where this lies
strcat(reg[num].codigo,c);
I get this error:
error: invalid conversion from 'char' to 'const char*' [-fpermissive]
How can I fix it?
Upvotes: 0
Views: 182
Reputation: 93
signature of strcat is char * strcat ( char * destination, const char * source );
in your code second parameter is char c, hence the issue
Upvotes: 1
Reputation: 11963
The signature of strcat
is char *strcat(char*, char*)
, but you're passing a char
as the second argument. The second argument needs to be a pointer to a char
... i.e. &c
... but that's not the whole solution... There are other issues here- all the c[0]
are incorrect, because c
is not an array of char
. I think in most of these cases you just mean c
.
Upvotes: 2