1

My exercise is to use a structure to initialise values and then print them (sounds easy enough) but instead of using the structure to print them, we have to use the pointer *p. I know this probably has a really simple answer, but help would be appreciated!

#include <stdio.h>
#include <string.h>

struct info
{
    int total;
    char *str;
};

int main()
{

    struct info s, *p = &s;

    s.total = 50;
    s.str = "hello";

    printf("Info total: %i\n", s.total);
    printf("Info *str: %s\n", s.str);

    return 0;
}
4
  • 1
    Have you heard about arrow operator ->? Commented Oct 23, 2015 at 22:01
  • Did you read you the paragraph on structures in the C book? Commented Oct 23, 2015 at 22:01
  • 1
    s.total <=> p->total or (*p).total Commented Oct 23, 2015 at 22:05
  • Thank you myaut and BLUEPIXY! I have got it to work now. And ouah, we don't have a module book this year, just a large book of notes written by the lecturer and there is no mention of this arrow operator. Commented Oct 23, 2015 at 22:08

1 Answer 1

3
s.total <=> p->total or (*p).total

Thanks to you all for the answers!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.