473,379 Members | 1,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Little Confused

#include<stdio.h>
#include<stdlib.h>

typedef struct binary* binaryptr;
typedef struct binary
{
int data;
binaryptr next;

}Binary;

void AddNum(binaryptr , int);

int main(int argc, char **argv)
{
int input,num;
binaryptr list;
list = NULL;
if(argc!=2)
{
printf("Arguments not enough\n");
exit(EXIT_FAILURE);

}
input = atoi(argv[1]);

while(input!=0)
{
num= input%2;
AddNum(list,num);
input /= 2;
}
while(list!=NULL)
{
printf("%d\n",list->data);
list = list->next;
}

return 0;
}

void AddNum(binaryptr list, int num)
{
binaryptr temp,NewNode;
printf("IN Add Num\n");
if(list == NULL)
{
NewNode = malloc(sizeof(Binary));
printf("IN List Null\n");
NewNode->data = num;
NewNode->next = NULL;

list = NewNode;

}
else
{
temp = list;
while(temp->next!=NULL)
{
temp = temp->next;
}
NewNode = malloc(sizeof(binaryptr));
NewNode->data = num;
NewNode->next = NULL;
temp->next = NewNode;

}

}

Why would i will not get the List through this code.
Each time i am entering if(list == NULL){
} Loop.

Is the reason is that i am allocating memory in the fucntion and when i
will return from that function that object may cease to exist.
I am passing a pointer to structure. So if i allocate some memory to it
in some function it should not sho itself as NULL.

Also if i pass pointer to a pointer to structure it works fine.

Why???

Thanx in advance
Vishal

Mar 22 '06 #1
0 1105

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two...
2
by: Charlie T | last post by:
Hello, I am a little confused... please help: ----------------------------------- <DIV id="01"> <DIV id="aNum"></DIV> <DIV id="bNum"></DIV> <DIV id="cNum"></DIV> </DIV>
1
by: Jeff Uchtman | last post by:
I have read 10000 opinions on returning random records and I am more confused now that before I started. I have a small access db that will contain 20 or so rows with 3 or 4 columns. I like to...
3
by: Laszlo Szijarto | last post by:
In using the BitArray class to parse a single byte, I noticed that the bits show up in Little Endian order. Aren't bits always arranged in Big Endian order? I'm a bit confused and would...
2
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
14
by: CMM | last post by:
Do the developers of Visual 2005 actuall use it??? There's lots of great things in VS2005 (mostly related to the outstanding work done on the CLR)... but in general the LITTLE THINGS totally drag...
6
by: manochavishal | last post by:
Hi , Ihave this code to show binary of an integer. #include<stdio.h> #include<stdlib.h> typedef struct binary* binaryptr; typedef struct binary { int data;
16
by: mdh | last post by:
Can someone look at this little program and tell me why the last line is not compiling. #include <stdio.h> int main (){ int i, j, k; i=0;
1
by: shapper | last post by:
Hello, I need to create a data object to hold a number of records with 3 columns. A datatable would do. My problem is this: 1. I will use this as a GridView datasource. 2. I will need to...
4
by: mattmao | last post by:
I am moving onto the tough part in learning C:( First, about the declaration of a user defined structure: I found this syntax in my lecture notes: struct userinfo { char username; ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.