473,386 Members | 1,644 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,386 software developers and data experts.

Problem with pointers, require some help

Hello, I am getting some problems with C and how it handles the
pointers. I will tell more about the situation: I have created my own
structure for making one way linked list. I have procedure int
createList(child *root) [child is that structure] and before that I
create pointer child *rootA, and then I invoke createList(rootA)
[*rootA holds the value, and rootA is the pointer, holds the address
as I remember]. And this function creates dynamic list, but the
problem is that rootA does not point to it. After creating list
function returns the length of it.

The question is, how should I send to function a pointer, create a
list in heap and then make that pointer to point to it?

It would be something like this:
int main {
int *item;
func(*item);
printf("%d", *item);
return 0;
}

func(int *num) {
num = malloc(sizeof(int));
*num = 8;
printf("%d", *num);
printf in func gives "8", but item still does not point to the same
memory where that number is located. But I want it to point. How?
}
Feb 5 '08 #1
6 1176
Small mistaking rewriting, should be "func(item);" in program. Any
ideas how to make it point to what I want?
Feb 5 '08 #2
Use a pointer to pointer.

You can read about it in any C programming manual.
Feb 5 '08 #3
Thanks for the help, I used pointer to pointer as a few people
suggested.

It is my first day with C programming language and I still collecting
books, websites and etc. with the most detailed explanation how
everything here works. Maybe you could recommend some good material?

And for ASM looks a lot easier comparing to C, but it looks that in a
week I will manage to write some good or at least better code than I
do now.

Thanks again.
Feb 5 '08 #4
david wrote:
Thanks for the help, I used pointer to pointer as a few people
suggested.

It is my first day with C programming language and I still collecting
books, websites and etc. with the most detailed explanation how
everything here works. Maybe you could recommend some good material?
Then this is not how you should approach learning. Get a basic tutorial
book. Read through it, working the exercises in each chapter. Then
start creating simple programs.

Brian
Feb 5 '08 #5
CBFalconer <cb********@yahoo.comwrote:
david wrote:

Small mistaking rewriting, should be "func(item);" in program. Any
ideas how to make it point to what I want?

See sig below.
--
Posted via a free Usenet account from http://www.teranews.com
What's so interesting about that?

Richard
Feb 6 '08 #6
santosh wrote, On 05/02/08 19:54:
david wrote:
>Thanks for the help, I used pointer to pointer as a few people
suggested.

It is my first day with C programming language and I still collecting
books, websites and etc. with the most detailed explanation how
everything here works. Maybe you could recommend some good material?

The C Programming Language (Second Edition) by Kernighan & Ritchie
<snip good suggestions>

Also the comp.lang.c FAQ which would have answered the OPs question. If
can be found at http://c-faq.com/
--
Flash Gordon
Feb 6 '08 #7

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

Similar topics

3
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store...
4
by: Leslaw Bieniasz | last post by:
Cracow, 20.09.2004 Hello, I need to implement a library containing a hierarchy of classes together with some binary operations on objects. To fix attention, let me assume that it is a...
5
by: Vivek | last post by:
Hi, I am trying to get as much information on void pointers. How do we take help of void pointers in writing generic functions. I have seen this kind of code for many years, but now I have got...
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
7
by: jsale | last post by:
I'm currently using ASP.NET with VS2003 and SQL Server 2003. The ASP.NET app i have made is running on IIS v6 and consists of a number of pages that allow the user to read information from the...
92
by: Jim Langston | last post by:
Someone made the statement in a newsgroup that most C++ programmers use smart pointers. His actual phrase was "most of us" but I really don't think that most C++ programmers use smart pointers,...
18
by: atv | last post by:
at least to me it is. I can't figure out for the life what it is i'm doing wrong here. i have a function called assign_coordinate. usually, i pass a malloced pointer to it, then individual...
8
by: cman | last post by:
What do pointers to pointers accomplish? How does having a pointer to a pointer help a design or aglorithm? Where are they normally used? cman
11
by: subramanian100in | last post by:
Given that the sizes of pointers to different data types(built-in or structures) can be different, though malloc returns a void *, it is assigned to any pointer type. The language allows it. From...
5
by: weidongtom | last post by:
Hi, I tried to implement the Universal Machine as described in http://www.boundvariable.org/task.shtml, and I managed to get one implemented (After looking at what other's have done.) But when I...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.