473,386 Members | 1,609 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.

getting size of pointer to an array

montzter
Guys,

I've got the below codes but having difficulty in reading the correct size of each data in an array of pointers. Can somebody help me out. ::::
//=================================================
static char* SomeName[]=
{
(char*) "abc",
(char*) "cdfdfnttel",
(char*) "ground1234",
(char*) "calc",
(char*) "unwanted",
(char*) "data",
(char*) "anything",
};

//==== my code===================

void SomeFunction(/*some parameters*/)
{
int b4SizeOfDatainList
...
...
b4indexFound = somefunctionReturnIndexofList();
b4SizeOfDatainList = sizeof(SomeName[b4indexFound]); // PROBLEM HERE!!!
...
...
}

//============================

Problem is that sizeof() function is only returning 4 always. I tried dereferencing the pointer but it just returned value 1....

can somebody help me out. Thanks a Lot!

Jun
Oct 19 '06 #1
1 2442
Guys,

I've got the below codes but having difficulty in reading the correct size of each data in an array of pointers. Can somebody help me out. ::::
//=================================================
static char* SomeName[]=
{
(char*) "abc",
(char*) "cdfdfnttel",
(char*) "ground1234",
(char*) "calc",
(char*) "unwanted",
(char*) "data",
(char*) "anything",
};

//==== my code===================

void SomeFunction(/*some parameters*/)
{
int b4SizeOfDatainList
...
...
b4indexFound = somefunctionReturnIndexofList();
b4SizeOfDatainList = sizeof(SomeName[b4indexFound]); // PROBLEM HERE!!!
...
...
}

//============================

Problem is that sizeof() function is only returning 4 always. I tried dereferencing the pointer but it just returned value 1....

can somebody help me out. Thanks a Lot!

Jun

Oh already got it..... its should not be sizeof() but strlen() since its NULL terminated i guess. thanks anyway....
Oct 19 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Wynand Winterbach | last post by:
I think every C programmer can relate to the frustrations that malloc allocated arrays bring. In particular, I've always found the fact that the size of an array must be stored separately to be a...
9
by: dati_remo | last post by:
Hi, is it possible to find the dimension of an array using a pointer? main() { int a; f(a); return; }
4
by: terry | last post by:
Hi, Could anyone tell me how to determine the size of array of characters dynamically? For example, : : char *a={"hello","hi","kitty"}; char *b={"orange","apple"};
10
by: nospam | last post by:
Hello! I can pass a "pointer to a double" to a function that accepts double*, like this: int func(double* var) { *var=1.0; ... }
18
by: bsder | last post by:
Hi, Can anyone please tell me how to calculate the size of the following 4-dimensional array, and now to use qsort for sorting on this array? double sp = { 4.0, 5.0, 6.0 }; double spa = { {...
22
by: Chad | last post by:
Given the following code include <stdio.h> #include <stdlib.h> int main(void) { char *msg_list = {" apple", " orange", " grape" }; printf("name: %s \n", msg_list);
29
by: Vasileios Zografos | last post by:
Hi everyone, I need to build a function to plug it in a program (that I didnt make or can change) that should be called something like this: float someFunction(float x) { ...
7
by: bowlderster | last post by:
Hello,all. I want to get the array size in a function, and the array is an argument of the function. I try the following code. /*************************************** */ #include<stdio.h>...
4
by: rakesh.usenet | last post by:
For a particular application of mine - I need a simulation of byte array output stream. * write data onto a stream * getback the contiguous content as an array later for network transport. ...
33
by: Adam Chapman | last post by:
Hi, Im trying to migrate from programming in Matlab over to C. Im trying to make a simple function to multiply one matrix by the other. I've realised that C can't determine the size of a 2d...
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: 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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.