Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Thank you for all your help!

In my header file I have :

typedef struct
{
    char name[10];
    char address[10];
    struct node *next;
} Link;



in the main code I have:

// linkedlist.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <Source1.h>

int _tmain(int argc, _TCHAR* argv[])
{
    return 0;
}


A couple of questions:

How do I use the structure in the header file in main file?
How do I use its members in the main file?
How do I make it global?

John
Posted
Updated 27-Nov-10 19:54pm
v2

1 solution

Assuming "Link" is in the file "source1.h", then just declare an instance of it:
#include "stdafx.h"
#include <Source1.h>

Link myLink;

int _tmain(int argc, _TCHAR* argv[])
{
    myLink.name[0] = 'A';
    return 0;
}
That gives you a global instance "myLink" and you can use it's members.
 
Share this answer
 
Comments
Member 3997606 28-Nov-10 21:25pm    
#include "stdafx.h"
#include <source1.h>
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

Link additems (Link *add)
^
|
suppose I want to return a pointer to the structure, how do I do this?
Member 3997606 28-Nov-10 22:25pm    
Link additems (Link *add)
{
Link *curr,*prev,*newptr;
char name[10];
char addy[10];
int maxitems;
int userpress;

newptr == malloc(sizeof(Link));
while (maxitems!=50 && userpress !=999)
{
printf("Enter in Name: (up to 10 chars)");
scanf("%c",&newptr->name);
printf("Enter in address: (Up to 10 characters:");
scanf("%c",&newptr->address);
if (newptr!=NULL)
{
prev=NULL;//No Previous item
curr=head;//current item is at the head
}
while(curr!=NULL&&newptr->name!=curr->name)
{
prev=curr;//sets the previous ptr to curr
curr =curr->next;//I get an error a value of type node cannot be assigned to type Link? What does that mean?? What is the solution?
}
if ( prev==NULL)
{
*newptr->next=head;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900