0

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?

Anish Ramaswamy
  • 2,326
  • 3
  • 32
  • 63
xikhari
  • 99
  • 3
  • 14
  • Possible duplicates: [Implicit cast from char** to const char**](http://stackoverflow.com/questions/7016098/implicit-cast-from-char-to-const-char) and [error: invalid conversion from ‘const char*’ to ‘char’ \[-fpermissive\]](http://stackoverflow.com/questions/12026567/error-invalid-conversion-from-const-char-to-char-fpermissive) – Devendra D. Chavan Mar 05 '13 at 04:44

2 Answers2

2

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.

gcbenison
  • 11,723
  • 4
  • 44
  • 82
  • thanks really I saw that c[0] but still got the error, couldnt figure out by myself the & thanks :) – xikhari Mar 07 '13 at 02:26
1

signature of strcat is char * strcat ( char * destination, const char * source );

in your code second parameter is char c, hence the issue

ddahuja
  • 93
  • 1
  • 1
  • 5