Sponsored Content
Top Forums Programming C pointer/array duality confusion Post 302427722 by gorga on Monday 7th of June 2010 03:51:37 PM
Old 06-07-2010
Thanx for your reply,

"you're trying to initialize a struct, from a pointer."

I thought with the typedef...

Code:
typedef section_t* region_t[SECTION_LENGTH];

This would mean that the following statement would be assigning a ptr to a ptr...

Code:
region_t region = ctn.regions[nth];

Because a region_t is a ptr type...or in other words, an array of section_t* ptrs. Hence my confusion, I thought in C an array and a ptr were essentially the same things, so this would work.

Anyway I got it to work by changing the assignment to the following...
Code:
section_t** region = ctn.regions[nth];

I realised that "ctn.regions[nth]" is basically an array without the subscript, which means it's a ptr. And what it points to is a ptr to a "section_t"... voila a ptr to a ptr.

And I can access the section_t* by using the subscript, i.e...

Code:
  region[i]->section_t_data_member = x;

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

confusion (file pointer and file descripter)

Hi everybody, i am newbie to unix and confused with file pointers and file descripters. could anyone help me to clear my doubts .. when we call unix system calls to create a file then we are dealing wih file descripters i think file descripters are also normals file as stored inhard disks... (1 Reply)
Discussion started by: johnray31
1 Replies

2. UNIX for Dummies Questions & Answers

Storing pointer array in C

All .. I am having a pointer array . And trying to store the addess into that pointer array . please see below the problem i faced code: int cnt1; char *t_array; char *f_array; for(cnt1=0; cnt1<1000; cnt1++) { t_array =... (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

3. Programming

pass a pointer-to-pointer, or return a pointer?

If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it: (1) one is to pass a pointer-to-pointer parameter, like: int my_malloc(int size, char **pmem) { *pmem=(char *)malloc(size); if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies

4. Programming

help with char pointer array in C

i have an array like #define NUM 8 .... new_socket_fd = accept(socket_fd, (struct sockaddr *) &cli_addr, &client_length); char *items = {"one", "two", "three", "four", "five", "six", "seven", "eight"}; char *item_name_length = {"3", "3", "5", "4", "4", "3", "5", "5"}; ... (1 Reply)
Discussion started by: omega666
1 Replies

5. Programming

structure pointer array as function parameters

if i create an array of pointers to a structure "struct node" as: struct node *r; and create "n" number of "linked lists" and assign it to the various struct pointers r using some function with a return type as structure pointer as: r=multiplty(.......) /*some parameters*/ is... (2 Replies)
Discussion started by: mscoder
2 Replies

6. Programming

Unclear pointer and array

Hello, The purpose of the program is to print a sub string from the prompt inputs. I do not understand why char pointer does not work but char array will for line 40 and Line 41. ./a.out thisisatest 0 8 substring = "thisisat"And my code is: #include <stdio.h> #include <stdlib.h> #include... (29 Replies)
Discussion started by: yifangt
29 Replies

7. Programming

Pointer confusion

Here are two programs that pass a pointer to a variable but behave differently. Shouldnt the i in second program be 0 after the function call? #include<stdio.h> void changeI(int *i) { *i = 10; } int main(void) { int i=5; printf("%d before\n", i); changeI(&i); printf("%d... (1 Reply)
Discussion started by: dragonpoint
1 Replies

8. UNIX for Dummies Questions & Answers

File System and Storage Array Confusion

Hi Friends, I have a host(Suse Linux 10.4) which has 2 luns presented from 2 different arrays HP eva and xp. we are planning to migrate hp eva to 3par. When i look for physical volume i see /dev/dm-4, /dev/dm-5, /dev/dm-7and when i look for multipath -ll i see dm-8,dm-9,dm-7. So i can't confirm... (6 Replies)
Discussion started by: munna529
6 Replies

9. Programming

Character pointer to Character array

how to copy content of character pointer to character array in c programming.. char *num; char name=num; (1 Reply)
Discussion started by: zinat
1 Replies

10. Programming

Pointer for 2D array seems to be 3D in C

I am struggling with the pointer to 2D-array (cf: 2D array of pointers). Can anybody help me elaborate how the pointer x moves in the memory to access the individual of y, especially the high lighted lines? I have talked to one of the curators of the forum, but I am still not quite clear. Here... (1 Reply)
Discussion started by: yifangt
1 Replies
SCANDIR(3)						     Library Functions Manual							SCANDIR(3)

NAME
scandir, alphasort - scan a directory SYNOPSIS
#include <sys/types.h> #include <sys/dir.h> scandir(dirname, namelist, select, compar) char *dirname; struct direct *(*namelist[]); int (*select)(); int (*compar)(); alphasort(d1, d2) struct direct **d1, **d2; DESCRIPTION
Scandir reads the directory dirname and builds an array of pointers to directory entries using malloc(3). It returns the number of entries in the array and a pointer to the array through namelist. The select parameter is a pointer to a user supplied subroutine which is called by scandir to select which entries are to be included in the array. The select routine is passed a pointer to a directory entry and should return a non-zero value if the directory entry is to be included in the array. If select is null, then all the directory entries will be included. The compar parameter is a pointer to a user supplied subroutine which is passed to qsort(3) to sort the completed array. If this pointer is null, the array is not sorted. Alphasort is a routine which can be used for the compar parameter to sort the array alphabetically. The memory allocated for the array can be deallocated with free (see malloc(3)) by freeing each pointer in the array and the array itself. SEE ALSO
directory(3), malloc(3), qsort(3), dir(5) DIAGNOSTICS
Returns -1 if the directory cannot be opened for reading or if malloc(3) cannot allocate enough memory to hold all the data structures. 4.2 Berkeley Distribution September 17, 1985 SCANDIR(3)
All times are GMT -4. The time now is 12:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy