Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

Posted on 1999-06-26
Medium Priority
189 Views
how we scanf if we have
struct stock{
char name;
struct stock *next_stock;
}goods;
struct customer{
struct goods things;
main()
{
scanf("%d",cust->?????????????????)

struct customer *next_cust;
}cust;
0
Question by:eddyhalim
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 3

Accepted Solution

BudVVeezer earned 20 total points
ID: 1263024
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

LVL 3

Expert Comment

ID: 1263025
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

LVL 6

Expert Comment

ID: 1263026
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

Expert Comment

ID: 1263027
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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
###### Suggested Courses
Course of the Month8 days, 23 hours left to enroll