• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

linked list

how we scanf if we have
struct stock{
char name;
struct stock *next_stock;
}goods;
struct customer{
char add;
struct goods things;
main()
{
scanf("%d",cust->?????????????????)






struct customer *next_cust;
}cust;
0
eddyhalim
Asked:
eddyhalim
  • 2
1 Solution
 
BudVVeezerCommented:
cust.things.name

since things is a part of the struct(not a pointer), you would use the ., not the ->.  If things was a pointer to a goods, then you would use the arrows.

~Aaron
0
 
BudVVeezerCommented:
btw, an easier definition would be:

typedef struct goods
{
char name;
struct goods *next;
}goods;

typedef struct cust
{
goods *things;
struct cust *next;
}cust;

then you would do

cust c;

c->things->name;

~Aaron
0
 
TriskelionCommented:
WATCH OUT!
Your "name" is only one character long

#include <stdio.h>
/**/
typedef struct goods
{
      char            name[50];
      struct      goods *next;
}goods;
/**/
void main(void)
{
      static      goods      xGoods;
      static      int      iResult;
      
      iResult = scanf("%s", xGoods.name);
      /*You will have to calculate the address of the next goods manually*/
      printf(" %d Fields converted\r\nYou entered:\r\n\t%s\r\n", iResult, xGoods.name);
}
0
 
prabhuramCommented:
If you want each element of the linked list cust to have a linked list goods, what the hell do you want to read as input and populate what fields? all of them in sequence?
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now