Programming :: C Realloc Resize Array / Delete And Add Information Into The Array?
Mar 6, 2011
I am trying to dynamically delete and add information into the array "blah"
Code:
int blahsize = 1;
char** blah = (char**) calloc(blahsize+1,sizeof(char*));
Adding information:
Code:
blah[1]=stuff1;
blah[2]=stuff2;
code....
View 2 Replies
ADVERTISEMENT
Jun 7, 2010
I have trouble converting a short array to a char array
Code:
short pShort[4] = { 0x41, 0x42, 0x43, 0x44 };
How to convert this to a char array?
View 4 Replies
View Related
Aug 9, 2009
I'm writing a PHP program. I've encountered a problem; in the following code I try to pass $_POST['delete'] which is an array as the value of a hidden input to some form, but it doesn't do so.there's something wrong with converting PHP array into HTML array. I'm sure that $_POST['delete'] is not null and is a real array.
echo '<input type="hidden" name="delete[]" value="'.$_POST['delete'].'" />';
View 4 Replies
View Related
May 26, 2010
(I am using vector() and matrix() functions from "Numerical recipes in C".)There are 100 numbers to be stored in 2D array of 10 rows and 10 columns.100 numbers are stored in a 1D array.I get "segmentation fault" at the line indicated in the segment of my code below:
Code:
:
:
#define size 100
#define nl 1
[code]....
View 12 Replies
View Related
Jun 20, 2010
I looked on the net for such function or example and didin't find anything, thus after having made one i guess it would be legitimate to drop it to see what others thinks of it.
#!/bin/bash
addelementtoarray()
{
local arrayname=$1
[code]....
View 10 Replies
View Related
Feb 27, 2010
I have a string problem with a function I am writing and I cant figure it out. I am trying to write unit test which will verify it works as expected. As I need to make use of it elsewhere and obviously robust and correct enough that I can rely on it. Okay first of all I define the following structure
Code:
typedef struct strarray {
int size;
char **elements;
} strarray;
code....
My problem is that upon the 4th iteration in the loop realloc fails in strarray_add. glibc reports invalid next size.
View 6 Replies
View Related
Dec 23, 2010
I have a RAID 5 array, md0, with three full-disk (non-partitioned) members, sdb, sdc, and sdd. My computer will hang during the AHCI BIOS if AHCI is enabled instead of IDE, if these drives are plugged in. I believe it may be because I'm using the whole disk, and the AHCI BIOS expects an MBR to be on the drive (I don't know why it would care).
Is there a way to convert the array to use members sdb1, sdc1 and sdd1, partitioned MBR with 0xFD RAID partitions?
View 1 Replies
View Related
Jun 4, 2010
This _almost_ works. I just can't quite get it to honor the spaces.
Code:
#!/bin/bash
profiles=(
PROFILE_ONE
)
PROFILE_ONE=(setting1 "setting number 2")
[code].....
View 9 Replies
View Related
Sep 27, 2010
I have a NETGEAR ReadyNAS NV+ with four 1TB drives in a RAID-5 array. This is our primary file storage. This has previously been backed up to a hardware RAID-0 array directly attached to our Windows server. The capacity of this backup array is no longer sufficient. So the plan was, take a bunch of 200GB to 320GB drives (And a 750) I had kicking around, chuck them in a couple of old SCSI drive enclosures I have collecting dust, attach them via IDA/SATA-to-USB adaptors to a USB hub, attach that to the server, create a JBOD array spanning the disks, and back up the NAS to that. Performance is not an issue as this is just to be used for backup, with the idea being as near to zero cost as possible (Spend so far = NZ$100�ish).
The first hurdle I struck was Windows not supporting Dynamic Disks on USB drives (Required to create a spanned volume). At first I resisted using another machine (i.e. a machine running Ubuntu) as I didn't want to dedicate a piece of hardware to backing up the NAS. I then decided it would be acceptable to do this via a VM, which is what I've done.So I have 10.04 running under VMWare Server 2.0.2 under Windows Server 2008 R2. The disks are all presented to the VM. I wasn't sure if I was going to end up creating the array under LVM or something else, but I noticed Disk Utility has an option to create an array, so I tried that. When I add two 250GB drives, the array size is 500GB. When I then add a 160GB drive, the array size drops to 480GB. Huh? If I keep adding disks (Regardless of order) the final array size comes out at 1.8 TB, as per the attached screenshot. Now with the following drives, I expected something more like:
160 + 250 + 250+ 750 + 250 +200 + 200 + 250 + 320 + 250 + 320 = 3.2TB
Am I missing something or making a false assumption somewhere?
View 4 Replies
View Related
Dec 2, 2010
I have an array called arrayini which stores numbers. I want to take log to the base 2 of each of the numbers in that array and put it in file called result. I've used the following code to do it.
Code:
size=${#arrayini[@]}
for ((i=0;i<size;i++))
do
echo "scale = 12; l(${arrayini[$i]})/l(2)" | bc -l
done >result
It works fine but its taking pretty long to calculate since I've got about 230,000 items in the array. So I decided to store the result into an array hoping that it'd be faster. I tried the following code. arrayresult is where I try and store the result. The code doesn't work because of the second last line.
Code:
unset arrayresult
size=${#arrayini[@]}
for ((i=0;i<size;i++))
do
arrayresult[$i]="scale = 12; l(${arrayini[$i]})/l(2)" | bc -l
done >FILE2
There is a syntax error clearly.
View 6 Replies
View Related
Sep 24, 2010
This array is supposed to contain 12 elements (names of the month) What I want to achieve is that depending on some user input (a number 1-12) a full name of one of the months will be displayed, eg.
Code:
scanf("%d", &month);
printf("The month is %c", months_names[month]);
View 6 Replies
View Related
Feb 18, 2010
I am trying to create an array containing all ASCII characters, how do I create one:
Code:
#!/bin/bash
CHARLIST=( a b c d e f g h i j k l m n o p q r s t u v w x y z
[code]...
View 6 Replies
View Related
Oct 29, 2009
I've got a problem...
a[0] = 22
echo $[a[0]]
echoes 22 - that works fine
[code]...
View 5 Replies
View Related
Mar 27, 2010
I wonder why arrays in the C programming language are pointers to the first element of the array, not the first element of the array itself?
View 14 Replies
View Related
Apr 4, 2010
I have a text file from which i read a number of names with their lengths at the run-time.Now i want to created a char array having the length and name as already read from the text file at the run-time. There is no compilation involved. Every thing is happening at the run-time. I tried using STL like map along with malloc but i am unable to name an array at run-time. I can keep some type of mapping with previously created arrays
View 3 Replies
View Related
May 9, 2010
I've searched around and can't find out how to convert a string ( like "12345" ) into an int array ( x[ 5 ] = { 1, 2, 3, 4, 5 } ; ).
View 4 Replies
View Related
Jul 9, 2010
i am trying to represent alphabet into a array, and then i can count the frequency
for example
array[a]=0
array[b]=0
but i find the index of the array seems to be
array[1]=0
array[2]=0
I was try this way get the ascii for them, actually I have done this in java and it is simple.
something like this format
array[ascii{a}-ascii{a}]=0
array[ascii{b}-ascii{a}]=0
I have done a lot of searching , but cannot get what I want.'%d' "'$char" like this would not work.
View 2 Replies
View Related
Aug 5, 2010
how to sort the 2 dimensional array below by column 1 then by column 2?
22 55
2222 2230
33 66
44 58
222 240
[Code].....
this is a small part in my awk script. the input data is not in file, but it was manipulated in my script.
View 6 Replies
View Related
Jun 3, 2011
[code]...
I manage to write apr4sens into file,works fine.But how to write it into array,which I could later reshape and so on. I tryied like this
group=apr4sens. It doesn't work.
View 1 Replies
View Related
Apr 13, 2010
i have a loop which produces new value everytime it runs. i want to store the results in an array. how can i do dat??
loop is like:
a=0
declare v
while ((....))
do
v[$a]="$r"
let a=a+1
done
while doing this it is not treating v as array but as variable and it is overriding the value and old value is lost..i am using bash shell version 3.00.15
View 5 Replies
View Related
Oct 16, 2010
Here is statement.
$1[0]=0
$1 is an argument which is actually and array. In function we want to assign a value 0 of it's first content. But it's wrong way. Anybody know the right way to assign value in function by passing as argument.
View 3 Replies
View Related
Nov 28, 2010
Is it possible to have an array in Bash that can hold more than one value per item?
For example I would like an array like this:
Entry 1: apple, green
Entry 2: banana, yellow
And be able to call the fruit names and their colour in a list. Something like:
for fruit in "${array[@]}"
do
echo a $fruit is $colour
done
If that is possible, is there a limit to values per item? For example some entries in an array could be:
Entry 1: apple, green, round, pips, tree
Entry 2: banana, yellow, long, skin, tree
And I would like to pick out the values such as #3 being "round" and "long".
View 3 Replies
View Related
Aug 2, 2010
I believe I have unwanted ' characters left in a 9 element character array that are causing subsequent operations with it to fail. I see wildly differing views on the web on the proper way to flush 'em. It's clearly not as simple as it would appear at first sight. What's currently the best (or else "least deprecated") method?
View 5 Replies
View Related
Mar 7, 2011
Can you create a dynamic string array and using calloc(),realloc()?
Like:
Code:
string* x;
x = (string) calloc(x,sizeof(string));
View 9 Replies
View Related
Jan 27, 2010
With array in php. All I was having the following columns:
Code:
Now Like the Above there were more variables defined through script:
Code:
Now what the above code is doing is calculating average of above values from columns{1-?,4-?)..likewise
Say If I remove two Machine and calculate the avg.
View 1 Replies
View Related
Aug 1, 2010
Can I predefine constant array in c? with constants i do #define NAMEOFCONST value.is it possible to do this for an array? And if not I would like to know why. I suspect it has to do with memory handeling and pointers.
View 14 Replies
View Related
Jul 2, 2009
The idea is to make a website to check the availability of domains and it works but its not pretty yet. Below is what i have till so far:
## this is the API from my domain registrar.
<?php $client = new SoapClient('http://api.sync.com/?wsdl');
## I have a search box that sends the request to this page
$var = $_GET ["s"];
## remove the most common subdomains from the request.
$var=eregi_replace("www.", "", $var);
$var=eregi_replace("mail.", "", $var);
$var=eregi_replace("ftp.", "", $var);
$var=eregi_replace("pop.", "", $var);
$var=eregi_replace("smtp.", "", $var);
## remove any TLD extension from the request.
$split = explode(".", $var);
$main = $split[0];
$arraysize = sizeof($split);
for ($x=1; $x<$arraysize; $x++) {
$tld .= "." . $split[$x];
}
## login to the API
$paramLogin = array('handle' => 'randall', 'password' => 'password');
## match the domain with any possible TLD
$varcom = $paramAvailDomain = array('sld' => $main, 'tld' => 'com');
$varnet = $paramAvailDomain = array('sld' => $main, 'tld' => 'net');
$varorg = $paramAvailDomain = array('sld' => $main, 'tld' => 'org');
$varbiz = $paramAvailDomain = array('sld' => $main, 'tld' => 'biz');
$varinfo = $paramAvailDomain = array('sld' => $main, 'tld' => 'info');
$vareu = $paramAvailDomain = array('sld' => $main, 'tld' => 'eu');
$varnl = $paramAvailDomain = array('sld' => $main, 'tld' => 'nl');
$varbe = $paramAvailDomain = array('sld' => $main, 'tld' => 'be');
$varde = $paramAvailDomain = array('sld' => $main, 'tld' => 'de');
$varcouk = $paramAvailDomain = array('sld' => $main, 'tld' => 'co.uk');
$varorguk = $paramAvailDomain = array('sld' => $main, 'tld' => 'org.uk');
$varname = $paramAvailDomain = array('sld' => $main, 'tld' => 'name');
$varmobi = $paramAvailDomain = array('sld' => $main, 'tld' => 'mobi');
$varin = $paramAvailDomain = array('sld' => $main, 'tld' => 'in');
$vartv = $paramAvailDomain = array('sld' => $main, 'tld' => 'tv');
$varcn = $paramAvailDomain = array('sld' => $main, 'tld' => 'cn');
$varws = $paramAvailDomain = array('sld' => $main, 'tld' => 'ws');
$varnu = $paramAvailDomain = array('sld' => $main, 'tld' => 'nu');
$varbz = $paramAvailDomain = array('sld' => $main, 'tld' => 'bz');
$varcc = $paramAvailDomain = array('sld' => $main, 'tld' => 'cc');
## this requests the domain.COM and domain.NET
$varcom;
$varnet;
?>
<div id="content">
## below prints the result
<?php
print "<html><body><pre>";
$result1 = $client->__soapCall('Login', $paramLogin);
echo "<b>Result Login:</b>
" . print_r($result1, true);
$result15 = $client->__soapCall('AvailabilityDomain', $varcom);
$resvarcom = var_dump($result15, true);
$result15 = $client->__soapCall('AvailabilityDomain', $varnet);
$resvarnet = var_dump($result15, true);
print "</pre></html>";
?>
<?php
## the returned array looks like this
Result Login:
Array
(
[code] => 200
[message] => Login succesful
)
array(3) {
["code"]=>
string(3) "200"
["message"]=>
string(20) "Domain not available"
["result"]=>
object(stdClass)#236 (1) {
["status"]=>
string(5) "TAKEN"
}
}
bool(true)
array(3) {
["code"]=>
string(3) "200"
["message"]=>
string(16) "Domain available"
["result"]=>
object(stdClass)#232 (1) {
["status"]=>
string(4) "FREE"
}
}
bool(true)
?>
## till so far it works
What I need to do is to make this ugly looking reply in to something more readable, basically if TAKEN print occupied and if free print its yours to grab. I have been struggling with the in_array function but i'm not getting anywhere close in getting it to work.
View 2 Replies
View Related
Feb 12, 2010
I was thinking about how to make a dynamic array in C, and I thought that it would be much better if it could accept any data type. Is this possible? Of course I thought about void pointers, but how do I store the actual data?
View 7 Replies
View Related
Jun 30, 2011
I'm trying access binary records that were created in Borland Delphi and stored in a SQL Server database (as a BLOB). What the heck is the syntax for accessing a two-D array in C#? Here's an example:
Code:
const
MAX_BOWLERS = 8;
gMAX_FRAMES = 40;
...
type
[code]...
I've successfully got a valid "GameRec" over to C#-land. I want to access array element "GameRec.Frames[iBowler, iFrame]".
How do I define a C# type "TFrames = Array[1..Max_Bowlers, 0..gMax_Frames] of TFrame;" so that I can do it?
View 4 Replies
View Related
May 23, 2010
I have never used multidimensional array for a long time so please consider this as a newbie question. I am editing a program that uses a 4 dimensional array and I think I'm losing track of the indexes.
day = 0 to 30
hour = 0 to 23
channel = 0 to 7
len = 0 to 63
unsigned char idx[day][channel][hour][len];
I have seen that the assignment to a string is
snprintf(idx[day][hour][channel], 64, "%s/%s", dayofmonth, hourofday);
Is this correct? Because when I access with a day argument, that day value goes into the hour part.
View 9 Replies
View Related