Programming :: Can't Access To Content Of Array In For Loop
Mar 7, 2010
When I deal with an array in a function I con not access to the content of array in a for loop, but out of a for loop I can access to them! for example
[code]...
In a function when I send as parameter, in a for loop it prints the content of array and out of a for loop it prints the address of arr[i]
View 5 Replies
ADVERTISEMENT
May 26, 2011
I need to know how to assign a result from a select. I am clueless on the sytax. I am trying this in bash. Maybe I am not assigning the array right. It gives me the whole row in the echo instead of just field a. How do I get fieldA = a in the select. Note script was stripped for security on database info but the syntax is same.
Code:
#!/bin/sh
results="$(mysql --user ${DB_USER} -p${DB_PWD} ${DB_NAME} -Bse 'select a,b,c,d from tblMytable')"
for rows in "${results[@]}"
do
fieldA=${rows[0]};
echo ${fieldA};
done
View 2 Replies
View Related
Nov 6, 2010
Program in CSay I have a char array of 1024 bytes called buf1.But I only want to print the chars in index 0 up to index 30. I know I could do this with a for loop. But is there any other way? What about maybe storing from 31-1024 to another char array say buf2 with strcpy and somehow popping 31+ out of the buf1 char array?
View 3 Replies
View Related
Feb 2, 2011
I work in a simulations environment. I'm trying to write a bash script that will read fields from a .csv file into an array, the first field being an identifiyng number and the second field being a corresponding url. There are about 1600 of these number/url combinations in the .csv file that i'm reading from. Once that is done i want it to parse a text file and match the number, when it has a match i want it to enter the corresponding url into a particular line in the text file. The script I have written (with the help of the people on this forum a while back) does this well, but now I have a lot more data to parse. I think the script itself is explanatory enough to see what i'm doing. What i would like to do is cut it down to one while loop nested inside another loop so that I don't have 1600 or so elif statements. I can't figure out how to increment the output of the array. for instance, the first cycle would find the number that matches ${record1[2]} and input the url stored in ${record1[3]}. the next cycle would match ${record1[4]} and input the url in ${record1[5]}, and so on, does that make sense? The code is below and a sample .csv and text file are attached.
[Code]...
View 14 Replies
View Related
Jul 22, 2011
I'm reading "OReilly Learning Perl 5th Edition", and there are such words:Code:You can use an array element like $fred[2] in every place? where you could use any other scalavariable like $fred.At the bottom of the page, it explains the ? like this:Code:The most notable exception is that the control variable of a foreach loop, which you?ll see later in this chapter, must be a simple scalar.Since Perl has the save-and-restore mechanism for the control variable, why an array element can't be used as the control variable
View 1 Replies
View Related
Aug 21, 2009
I'm trying to read content of file to variable and use this variable in for loop. The problem is, when I have c++ comment style in file - /*. Spaces in line are also interpreted as separated lines.
For example:
Code:
Changing $files to "$files" eliminate these problems but causes that whole content of variable is treated as one string (one execution of loop).
View 6 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
Jul 7, 2010
I am in need of some syntax help. I'm trying to figure out how to store and retrieve an array out of a hash of hashes. For this example, I'm trying to access the city list for a particular state for a particular country. I understand I could do a join and split on the hash key to combine Country and State, but trying to keep things separated.The code I have gets in all the information for the Countries, and states, and gets the list of cities together, no problem. I store all the city names in an array, then make an anonymous pointer to the array for the hash, like this - $MY_CITIES{$COUNTRY}{$STATE} = [@CITIES]I believe that syntax is correct, or is it? What I'd like to do is I need to cycle through every hash to find if a city exists or not. If it exists in 3 states, then it should print 3 times. Here is the code block to search -
Code:
for $COUNTRY (@LIST_OF_COUNTRIES) {
for $STATE ( keys %MY_CITIES{$COUNTRY){$STATE} ) {
[code]...
View 4 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
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
Mar 31, 2011
I need to rename the resulted searched files from a loopI have the following code:
find . -name DOC* | while read i
do
find $i -type f -name '*.txt'
done
basically, I am searching for all txt files inside any folder starting with DOC name.this code is working fine with me.I need to rename those .txt files to .txtOLDOS: Ubuntu 10.4Bash shell
View 10 Replies
View Related
Jun 17, 2010
I am traveling outside US and trying to watch netflix from my computer.
However, it is blocked in my region. Is there a way to fake the IP address to looks like i am viewing the content from the US?
View 2 Replies
View Related
Jan 14, 2010
Earlier when installing Karmic I requested assistance to enable me to listen & view BBC content in the United Kingdom. This involved me in loading :
mozilla-mplayer,
flashplugin-nonfree,
Ubuntu restricted extras
which worked a treat.
I decided to install Karmic on an old desktop system with the intent of using it as a backup system for my data. Having installed this as a fresh install I again followed the earlier advice only to find that when I attempted to connect to the BBC I was asked to load flash. This happened no matter which station I attempted to listen or view.
As far as I can see everything has been installed exactly as on my laptop and therefore should naturally work as before. The only difference is the laptop is using 64 bit and the desktop 32. Since I now see that the desktop is also capable of 64 bit processing should installing the 64 bit Karmic help?
Using sysinfo does not give too much information. I am told that the CPU is an AMD Athlon 64x2 Dual Core processor 4400+, 1000.000 MHz & L2 cache 512. The graphic card is shown as VGA Compatible Controller and the Sound Card as a multimedia Audio Controller.
I am at a loss why I am being asked for flash on the desktop and not being able to have the same benefits as I have on my laptop running the same OS.
View 9 Replies
View Related
Sep 2, 2010
I installed Ubuntu within (along side) windows, But ubuntu is only showing me the 17GB that was dedicated to Ubuntu in My Computer. Is there a way to access everything on the hard drive even the stuff that's on the Windows 7 side?
View 3 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
Mar 29, 2010
I am in one of those terrible situations...My motherboard died and I am left with a nvidia nforce raid stripe set that I need to get data off. I guess I should have setup that backup regime. Some search results have suggested that dmraid may be my white knight. I have pulled the data off each of the disks (3 of them) into image files (using ddrescue) and created loop devices (/dev/loop[1-3], using losetup).
I am running 32bit ubuntu 9.10 btw. When I do a "dmraid -ay" it tells me it found a raid set but has not activated it. When I do a "dmraid -r" it tells me I have a raid5 array on one of my /dev/sd? devices. dmraid seems to be ignoring my loop devices . Does anyone know if dmraid actually works with loop devices? If it does is there a way for me to point it directly at the devices and get it to do its auto-magic?
View 1 Replies
View Related
Feb 9, 2011
i can not figure out why my program does not terminate if i type n when i read loop unless it is the last if statement in my program ?
while [ "$loop" = y ] ; do
echo "what does baket mean: " ; read word
if [ "$word" = why ]
[code]....
View 3 Replies
View Related
Oct 3, 2010
Here is my code
Code:
I just cant seem to understand loops. i havent put the loop in yet but what i would like is the user only to have 3 tries at guessing number then exit if wrong or it says "correct if right" tbh i dont even know if the above code is correct. i have tried several ways and position of the loops but each time is comes out wrong
View 7 Replies
View Related
Mar 25, 2011
I have a directory file capturing script, the variable is fine with in the loop but gone after the loop is done:
Code:
DIR="/usb/sdb1/media/music/"
i=1
[code]...
View 9 Replies
View Related
Jan 7, 2011
i made a program to read from a specific site whats on tv in that day.My question is if some of you have an idee how can i figure it out,what are movies,what are sports,what are shows ?
View 3 Replies
View Related
Apr 24, 2010
I am about to move my scripts to the next generation level, so I need some help I am stuck in varying my variable names in a loop. For example:
for user in ben dorothy mike pat
do
[ -r /home/$user ] && let "$user"check=1 || let "$user"check=0
[code]...
View 1 Replies
View Related
Jun 28, 2010
I am trying to do some shell programs. I tried some sites regarding the while loop, they give the structure as:
Code:
while [ n1 -lt 500 ]
do
echo $((n1+100))
done
But the below code also worked for me:
Code:
while ((n1 > 500))
do
echo $((n1+100))
done
By using (( )) I could use while, for. But the documentations didnt follow this way. I mainly use this for datastructure programming.
View 4 Replies
View Related
Aug 1, 2010
In the code segment below is a for loop I am having some considerable difficulty with. It just keeps iterating endlessly and totally ignores the 70 times limit specified. I can't ever remember having this problem before and am absolutely Clueless.
Code:
for ( x = 0; x < 70; x++ )
{
fputs ("CSN00", target);
fprintf (target, "%d", userid);
[Code].....
View 14 Replies
View Related
Nov 3, 2010
I've got a 'nested' for loop which has a grep in it, if the grep fails there's no output - however the error code is still $0 and the second for loop is still entered, there's also a grep in the second for loop.I guess ultimately what i need to know is whether there's a way of making grep generate an error code. when no results are found?
View 14 Replies
View Related
Apr 23, 2011
I want to loop through the records in the below file (homedir.temp)
/home/user1
/home/user2
/home/user3
I want to do the following activities with each record1. du -s - to get the total usage for that directory (my variable name is SIZE)2. divide SIZE by du -c for /home to get the percentage of usage. (my variable name is PER)3. write the directory, SIZE, PER to a filePROBLEMI am using the below for loop: for record in homedir.tempthe mentioned activitiesdonehe above is not looping through the records. It does the first record perfectly and exits the loop.
View 14 Replies
View Related
Apr 25, 2010
ITT and am just lurning about scripting and need to read a file and output the file to the screen. We need to do this with a while loop.
View 5 Replies
View Related