HI,
i want to declare an array that should accept any size given by the user.how to declare such array?please explain me with the help of a code..it should display on the screen "enter the no of rows" and" enter the no of columns" and it should accept any size specified by the user.
6 2150 gpraghuram 1,275
Recognized Expert Top Contributor
Hi,
You cant declare dynamic array,but u can achieve it using pointers. -
char **myArray;
-
myArray=(char**)malloc(sizeof(char*)*(ROWSIZE));
-
for(i=0;i<ROWSIZE;i++)
-
{
-
myArray[i]=(char*)malloc(COLSIZE);
-
}
-
Here ROWSIZE and COLSIZE are the inputs given by the user dynamically.
Thanks
Raghuram
Hi,
You cant declare dynamic array,but u can achieve it using pointers. -
char **myArray;
-
myArray=(char**)malloc(sizeof(char*)*(ROWSIZE));
-
for(i=0;i<ROWSIZE;i++)
-
{
-
myArray[i]=(char*)malloc(COLSIZE);
-
}
-
Here ROWSIZE and COLSIZE are the inputs given by the user dynamically.
Thanks
Raghuram
thankyou sir, but is it not at all possible to simple arrays to achieve that.i dont want to use pointers for this,isn't there any other way of doing it?
gpraghuram 1,275
Recognized Expert Top Contributor
HI,
Array size are needed during compile time, so u cant specify the size during run time.
U can achieve this only using pointers in C.
Thanks
Raghuram
HI,
Array size are needed during compile time, so u cant specify the size during run time.
U can achieve this only using pointers in C.
Thanks
Raghuram
the array that i have taken is an image.the image i have saved using .TXT format and actually i have to read the image values and classify that and finally i have to store the result in another array.the image i have is 400 by 800.but my program to read the array should be generic so that if i have a bigger image to read, it shouldn't create any problem and accept the user desired value.one more thing that is i declare an array of size[120][120],it is taking,but not more than that.and if i declare size[10][2000],then it is accepting.why is it that if i decrease the value of row and increase the value of column it is taking?
HI,
Array size are needed during compile time, so u cant specify the size during run time.
U can achieve this only using pointers in C.
Thanks
Raghuram
the array that i have taken is an image.the image i have saved using .TXT format and actually i have to read the image values and classify that and finally i have to store the result in another array.the image i have is 400 by 800.but my program to read the array should be generic so that if i have a bigger image to read, it shouldn't create any problem and accept the user desired value.one more thing that is i declare an array of size[120][120],it is taking,but not more than that.and if i declare size[10][2000],then it is accepting.why is it that if i decrease the value of row and increase the value of column it is taking? please help me with this confusion.thank you.
the array that i have taken is an image.the image i have saved using .TXT format and actually i have to read the image values and classify that and finally i have to store the result in another array.the image i have is 400 by 800.but my program to read the array should be generic so that if i have a bigger image to read, it shouldn't create any problem and accept the user desired value.one more thing that is i declare an array of size[120][120],it is taking,but not more than that.and if i declare size[10][2000],then it is accepting.why is it that if i decrease the value of row and increase the value of column it is taking? please help me with this confusion.thank you.
actually system doesnt knw abt ur size.... it only knw aboutsizes in bytes only. if u declare as like size[9][9] then we can store 9*9 values.... lik wis if u declare as lik [120][120] then may be it wil take much more spaces... but reason is this only......
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Michael Drumheller |
last post by:
(If you're not interested in NumArray, please skip this message.)
I am new to NumArray and I wonder if someone can help me with
array-indexing. Here's the basic situation: Given a rank-2 array
(i.e., a matrix) it seems to be trivial, with array indexing,
to extract a subset of its *columns*. But it does not seem
to be trivial to extract a subset of its *rows*. The code
snippet below describes the problem (if it really is a problem)...
|
by: Linda |
last post by:
How can I declare a two dimention array of character with dynamical
first dimention and static second dimention using mix of pointer* and
. I think "char *A" means first dimention is static and second
dimension is dynamical. Thank you.
|
by: raxitsheth |
last post by:
I am using array in my progrm...
is there any tool /tips so that i can convert my program to Dynamic
Array...so that I can Add more Element to Array....
Code is around 4000 line 'C' (not C++) program....
|
by: Krish |
last post by:
How do you find out the number of rows in the array {Array}
I have
.....
thanks
|
by: |
last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily
complicated than the other languages I know. I feel this is because there
aren't many good official resources out there to help do the most basic
things.
One of the "basic" things I haven't been able to find out how to do is how
to delete an item from a multidimensional array object and resize it
afterwards.
It seems so easy to conceive of the code to delete...
| |
by: Martin Pöpping |
last post by:
Hello,
I want to iterate the second dimension of a 2-dim-array.
Let´s say I have an array:
double myArray and a given index: int i.
Assume my index is given in want to iterate my array with something like
this:
|
by: ottawajn |
last post by:
Hi, There,
I want to declare a two-dimension array by
"float coeftemp1 ;" in Dev c++. It doesn't work.
But, if I change it to "float coeftemp1 ;".
It works. Could any one know the reason?
Thank you,
|
by: =?Utf-8?B?RGFya21hbg==?= |
last post by:
Hi,
I am wondering how you multi-dimension an array function?
My declared function looks like this:
Public Function GetCustomerList(ByVal Val1 As String, ByVal Val2 As Long,
ByVal Val3 As String) As String()
Previously I dimensioned a single dimension Array to the size I wanted and
|
by: yeshello54 |
last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error when i do the following. if you add a contact with up to 13 fields it will be stored in a data structure. i have a tabbed pane that will show six of the 13 fields for that contact. when you double click the contact i want it to pop up and show all 13...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |