Rename a String in a Vector of Structures [duplicate]

0

Good afternoon guys, I'm locking in a part of my code and I do not really know the logic to solve it.

If the manufacturer name of the vector carros at position j is equal to Chevrolet , change it to GM .

for(j = 0; j < qtd; j++) {
    if(carros[j].fabricante == "Chevrolet") {
       carros[j].fabricante = "GM";
    }
}
    
asked by anonymous 28.06.2017 / 21:06

1 answer

2

Use the strcmp function. Additionally, you need to use the strcpy function to assign the GM value. Both are defined in the header string.h

for (j = 0; j < qtd; j++) {
    if (strcmp(carros[j].fabricante, "Chevrolet") == 0) {
       strcpy(carros[j].fabricante, "GM");
    }
}
    
28.06.2017 / 21:12