Home > database >  How I attribute the word in c, I'm having a hard time doing it
How I attribute the word in c, I'm having a hard time doing it

Time:12-03

I'm having trouble assigning words in a character.

image

CodePudding user response:

You can't initialize a char[] array like that when it is a member of a struct (also, == is the equality comparison operator, = is the assignment operator).

You will have to use strcpy()/strncpy() instead after creating an instance of the struct, eg:

struct Livro livro;
strncpy(livro.editor, "Abril", 10);

CodePudding user response:

In C you can do so via the following method:

char editor[10];
strncpy(editor, "Abril", 10);

CodePudding user response:

In C, you cant directly initialize a string (char ) in a struct, and you have to initialize your struct into a function before. And after that you'll have to use your char[] or char like this :

  •  Tags:  
  • c
  • Related