How will i check the size of an array?

March 12, 2011 at 03:28:54
Specs: Windows 7
char *a ;
gets(a) ;

after getting any character how will i check the size of the array 'a' of n iteration?


See More: How will i check the size of an array?

Report •


#1
March 12, 2011 at 03:40:05
You haven't defined an array, just a pointer to a char. They are not the same thing. And as you have never initialized that pointer you will get, at best, unpredictable results; most likely the program will crash. Uninitialized pointers are not good news.

Report •

#2
March 12, 2011 at 04:28:49
i need an unlimited sized array....

Report •

#3
March 12, 2011 at 04:50:33
If you don't know how much storage you need then a simple array is not the appropriate data structure. Use a linked list or something similar.

There are ways to dynamically expand arrays, but you need to program it yourself, and it's not clean.

None of this means that you can use pointers without allocating some memory for them and initializing the pointer to point to that memory.


Report •

Related Solutions

#4
March 12, 2011 at 08:57:06
Thanks ijack....

Report •

#5
March 12, 2011 at 20:22:36
int_man:

Check out these links:

http://www.computing.net/answers/pr...
http://www.computing.net/answers/pr...

It describes allocating memory in "C" and also using the sizeof operator.


Report •

Ask Question