Renaming a string in a structure vector

Asked

Viewed 19 times

0

Good afternoon guys, I’m catching on to a part of my code and really don’t know the logic to solve it.

If the vector manufacturer’s name carros in position j be equal Chevrolet, change him to GM.

for(j = 0; j < qtd; j++) {
    if(carros[j].fabricante == "Chevrolet") {
       carros[j].fabricante = "GM";
    }
}
  • *remembering that this is the only part of the code that is giving error, if you need all the code, let me know.

1 answer

2

Use the function strcmp. Additionally, you need to use the function strcpy to make the assignment of the value GM. 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");
    }
}
  • 1

    Brigand merchant :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.