Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 29-09-2008, 08:15 PM   #1 (permalink)
Apprentice
 
veddotcom's Avatar
 
Join Date: Jan 2004
Location: Patna/Bhopal
Posts: 83
Default Problem with Pointer in Structure


#include <stdio.h>
#include <conio.h>
#include <alloc.h>

/* structure containing a data part and link part */
struct node
{
int data ;
struct node * link ;
} ;

/* This is The Part of Programm*/
The Problem is when i m running This Program (of Linked List) Runs Properly But When i m Changing Code to As Below It Gives Error..It Says LINK is not Defined.



#include <stdio.h>
#include <conio.h>
#include <alloc.h>

/* structure containing a data part and link part */
struct node
{
int data ;

} ;
struct node * link ;

why i m getting problem when i defined the line (struct node * link Outside the Structure....
Thank You
veddotcom is online now  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 29-09-2008, 08:46 PM   #2 (permalink)
Back!
 
red_devil's Avatar
 
Join Date: Jun 2007
Location: Bangalore
Posts: 513
Default Re: Problem with Pointer in Structure

AFAIK, the second code portion implies a pointer to the structure while the first one is part of the structure...

u r getting the error cos you are trying to use a pointer { link } which does not exist.

{ define a link inside the structure itself as you have done in the first part of the code to overcome the error}
red_devil is offline  
Old 29-09-2008, 09:03 PM   #3 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Problem with Pointer in Structure

Yes, and the question is, why are you changing it that way?
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 01-10-2008, 12:10 PM   #4 (permalink)
Apprentice
 
veddotcom's Avatar
 
Join Date: Jan 2004
Location: Patna/Bhopal
Posts: 83
Default Re: Problem with Pointer in Structure

I m Agree with u That First One Declaration is Part of Structure and Second one is Pointer to Structure... NOw the Question is.. IF i have to Create a Variable Which COntains Address of Link List Then why We Can't Decalre the structure as follow :

structure node
{
int data;
int *link; /*instead of struct node *link */
}

IN this Declaration The link will also contain the address of integer type.. Plz Explain...
veddotcom is online now  
Old 01-10-2008, 08:41 PM   #5 (permalink)
Back!
 
red_devil's Avatar
 
Join Date: Jun 2007
Location: Bangalore
Posts: 513
Default Re: Problem with Pointer in Structure

man i'm not able to understand your question..can you please be a bit more specific ?
red_devil is offline  
Old 01-10-2008, 09:36 PM   #6 (permalink)
Legen-wait for it-dary!
 
dheeraj_kumar's Avatar
 
Join Date: Dec 2004
Location: Chennai
Posts: 2,471
Default Re: Problem with Pointer in Structure

You can do that, but you cant use the structure as a structure, but just as a block of memory. If you declare the link as a integer pointer, when you want to access the structure, you need to cast this integer pointer as a structure pointer which will point to your next node.

So simple, use the right datatype.

Its like this: 'A' is a character, you can store it as a integer(65 i think) but if you need to use it as a character, you need to cast it as a character.

int a = 65;
printf("%c", a);
__________________
If the Start Windows Restart when Windows starts check box is checked Windows Restart will start automatically every time Windows is started. - Actual excerpt from a windows program help file
dheeraj_kumar is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
structure of RAM bhaskar QnA (read only) 1 09-04-2008 08:43 PM
Software to browse the structure of a website ? VexByte Software Q&A 10 24-05-2007 07:00 AM
recovering data with same dir structure hansraj QnA (read only) 2 28-10-2006 05:07 PM
source code structure for antivirus mayank_y2k0 Software Q&A 1 12-02-2006 06:37 PM
Linux File Structure sujithtom Open Source 10 15-12-2004 02:10 PM

 
Latest Threads
- by clinton
- by soumya
- by Sujeet
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 11:13 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2