Expected const char * but argument is of type char

cpointersstrcmpstrcpystruct

This error keeps popping up and I don't know how to solve it.
Please help! the error pops up in this line:
---fscanf(ifp, "%s", archive.team[i].color);---

There is also a
"passing argument 2 of strcmp makes pointer from integer without a cast"
error in line:

---if (strcmp(archive.team[j].name, name) == 0){---

Here is a condensed version of my code—————————————————————————————————————————————————————————————-

#include <stdio.h>

struct dragon {
    char name[40] ;
    char color[40] ;
};
struct collection {
    struct dragon team[1000];
    int num_dragons;
};

int main() {

struct collection archive;

FILE * ifp = fopen("dragon.txt", "r");
int i, j, k, l, m, updates, n=0;
char directions, color, name, ADD, REMOVE, SEARCH, LIST, rem;

fscanf(ifp, "%d", &updates);
for (i=0; i<updates; i++){
    fscanf(ifp, "%s", directions);

    if (directions==ADD){
        fscanf(ifp, "%s", archive.team[i].name);
        fscanf(ifp, "%s", archive.team[i].color);
        printf("%s the %s has been added to the team.", archive.team[i].name, archive.team[i].color);
    }

   else if (directions==REMOVE){
        fscanf(ifp, "%s", name);
        for (j=0; j<updates; j++){
            if (strcmp(archive.team[j].name, name) == 0){
                strcpy(archive.team[j].name, "rem");
                strcpy(archive.team[j].color, "rem");
                printf("%s the %s has been removed from the team.", name, archive.team[j].color);
            }
        }
    }

    else if (directions==SEARCH){
        fscanf(ifp, "%s", name);
        for (k=0; k<updates; k++){
            if (strcmp(archive.team[k].name, name) == 0)
            printf("%s the dragon is currently on the team.", name);
        }
        for (l=0; l<updates; l++){
            if (strcmp(archive.team[l].name, name) == 0)
                n++;
        }
        if (n==0)
            printf("%s the dragon is NOT currently on the team.", name);

    }

    else if (directions==LIST){
        fscanf(ifp, "%s", color);
        printf("%s dragons:\n", color);
        for (m=0; m<updates; m++){
            if (strcmp(archive.team[m].color, color) == 0)
            printf("%s\n", archive.team[m].name);
        }
    }
}

Best Answer

Your declaration:

char directions, color, name, ADD, REMOVE, SEARCH, LIST, rem;

is totally wrong. You try to write a string to a single char. Even if you manage to compile that, execution of such code would cause a buffer overrun and unexpected behavior (AV most likely).

Comparisons

if (directions==ADD)

are also quite suspect, you compare some data with uninitialized char, which would not work for the obvious reasons. Usage of the fixed length arrays is also not very good idea, because any string greater than 39 symbols will cause buffer overruns.

Honestly, a recommend you rewrite your code using std::string for string storage and std::cin/cout for the input/output.

Lets analyze your code from the beginning: you define variable direction, which should describe what action should be performed on your data. This variable is a char, but you try to write some sting into it, so you most likely will get AV here. Then you try to compare your data with some ADD variable which had never been initialized, so contains random char from the stack.

To make current solution workable: 1. Change direction declaration to the char[40]; 2. Change ADD to char* ADD = "ADD"; (REMOVE, SEARCH, etc should be changed the same way); 3. Change comparison code to if(!strcmp(directions, ADD))