I have a struct defined as :
struct B{
struct B_test *class;
char* value;
}
how can I print the char value if I have function passing a struct as parameter as shown:
void print(struct B* e){
...
}
For example
puts( e->value );
or
printf( "%s\n", e->value );
provided that the data member value points to an array that contains a string.
Otherwise you need to know the number of actual elements in the pointed array.
If the data member value points to a single character then you can output it for example like
printf( "%c\n", *e->value );
void print(struct B* e){
printf("%s", e->value);
}
Accessing elements of a struct through a pointer is done with the ->
operator, not the .
operator.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.