Programming :: Sorting 2 Dimension Array?
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
ADVERTISEMENT
Sep 17, 2010
I am parsing through XML documents with a PHP script and creating an array because, as far as I know, I can manipulate arrays better than the features DOM gives me. That part is not as important, though. The array it produces though is multi-dimensional, but somewhat inconsistent. If I have the following XML:
PHP Code:
<domains> <domain>
<title>google.com</title> <bookmarks>
<bookmark>maps.google.com</bookmark>
<bookmark>news.google.com</bookmark>
<bookmark>mail.google.com</bookmark>
</bookmarks> </domain> <domain>
<title>bankaccount.com</title>
<bookmarks> <bookmark>login.bankaccount.com</bookmark>
</bookmarks> </domain> </domains>
To call the first bookmark from the first domain, it would be:
PHP Code:
$array['domains']['domain'][0]['bookmarks']['bookmark'][0]
To call the first bookmark from the second domain, it would be:
PHP Code:
$array['domains']['domain'][1]['bookmarks']['bookmark']
The problem is, I want to simply call bookmarks through a simply 'foreach()' or 'for()' function and the lack of consistency might be a problem, but the fact that some levels have a '0' array key and others do not is causing a problem.
View 1 Replies
View Related
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
View Related
May 10, 2011
I have a list of list and I'd like to sort the list according to the last value of each row.
Let's say we have the list
L1 = [ [1,2] , [4,6] , [78,-3] ]
I wish to get
L2 = [ [78,-3] , [1,2] , [4,6] ]
Is there a simple way to do that in python?
View 4 Replies
View Related
Nov 1, 2010
I have this dictionary file that has this format:
SUBSTITUTE_VALUE, Real Value
SUBSTITUTE_VALUE_2, Real Big Value
SUBSTITUTE_VALUE_HECL, Hardware Abstract
SUBSTITUTE_V, Valley Mem
I want to sort this file so the LONGEST Substitute Values are listed at the top ( so SUBSTITUTE_VALUE_HECL would be first in the list). Obviously I want to keep the related values tagging along with them, so the whole first line would be
SUBSTITUTE_VALUE_HECL, Hardware Abstract
Playing with sort This has me pretty close: sort dict.file -k1.1n,1
View 2 Replies
View Related
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
Jun 25, 2011
I have a problem to reorganize a spreedsheat using shell, I want to use "sort" to organize the first column (descending scale) and then organize the second column in an ascending scale related to the first column so that the final result should be that one displayed at the end of the message. I have tried "sort -r -n" but I don't know how to reorganize the second column related to the first column.
40.0 20.0 9
40.0 15.0 8
40.0 10.0 14
40.0 5.0 12
39.0 15.0 18
39.0 10.0 19
39.0 20.0 5
39.0 5.0 4
41.0 20.0 10
41.0 15.0 12
41.0 5.0 8
41.0 10.0 7
Solution:
41.0 5.0 8
41.0 10.0 7
41.0 15.0 12
41.0 20.0 10
40.0 5.0 12
40.0 10.0 14
40.0 15.0 8
40.0 20.0 9
39.0 5.0 4
39.0 10.0 19
39.0 15.0 18
39.0 20.0 5
View 14 Replies
View Related
Aug 23, 2010
QTreeView and QTableView have sort functions, but I need to sort a QListView, and for there to be no way for the user to turn off or reverse sorting.
View 11 Replies
View Related
Sep 21, 2010
I need a shell script which gathers the data from a remote XML file and then displays it according to my needs.. I need this for my job due to the fact that I need to keep track price changes of euro, usd, gold, etc. The XML file I am talking about is located at this page: here. The reason I am posting the URL is that I need to use curl to get this file and it does NOT have newlines after each tag. I thought that that would be a problem. Here is what I need from the script: 1) curl to get the page 2) make use of sed, awk, etc. to display its contents in a more structured and readable manner as shown below:
A: 64.125 (% -0.26)
B: 81.130 (% -0.32)
C: 1.4930 (% 0.00)
D: 1.9590 (% 0.36)
View 5 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
Mar 17, 2009
I just started programming in PHP so I haven't figured out how to do this yet, but I have a multi-dimensional array that I need to sort by one column. That's fine...but I need the sort to ignore case! Right now I have it sorted by 'name' (the other column is 'uid').
The problem is that by the default the sort is case-sensitive so the array looks like this:
Code:
Apple 4015
Banana 4011
Cherry 4045
avocado 4046
I want to be able to sort the the 'name' column in a case-insensitive manner so that the array actually looks like:
Code:
Apple 4015
avocado 4046
Banana 4011
Cherry 4045
How to accomplish this? Just FYI I'm not actually sorting the PLUs for fruits...but it was a simple example. I'm actually doing this for a Facebook application.
View 2 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
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
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
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
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