Programming :: Get A Variable To Work As The Index Of An Array?

May 3, 2010

I am having a little trouble with a Bash shell script that I am working on. It is intended to read the information out of a gedcom genealogy file and determine who has lived in a particular area and output a report based upon who lived in a given area (like the different sections of a bygdebok for example). I am having a number of issues.

1) I can't seem to figure out how to get a variable to work as the index of an array. For example, I am trying to use the variable $individual to count which individual is being read in from the .ged file, and once that is figured out, next I will read in the individual's name, so I would like to create an array of names using the variable

Code:
$individual
as the index of the array. However, if I try the code
Code:
name[$individual]=$lineoftext;

[Code]....

I included only the last few lines of output as to not take up too much space because the output goes on forever, but you get the point from the example. This output has nothing to do with what the final output of the program is intended to be like. It is merely a test to prove that the 2 variables in question are getting their date loaded in properly.

View 14 Replies


ADVERTISEMENT

Programming :: Copying An Array Of Structs To New Variable?

Jun 27, 2011

I had a question about threads and mutexes recently answered and a members' answer sparked a different problem.'Nominal Animal' in the post mentioned said I should hold a mutex only long enough to copy my data to a temporary variable and then output by reading that temp. Here's some code on this. I must be copying the array of structs wrong because when the gui thread reads the temp copy, I end up with lots of garbage. Even running through gdb verifies that different data is in the temp array-copy than in the original.How do I go about copying this array of structs to another variable correctly in the gui thread?

Code:
typedef struct
{

[code]....

View 7 Replies View Related

Programming :: Perl's Foreach Loop Can't Use An Array Element As The Control Variable?

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

Programming :: Eliminate "ISO C++ Forbids Variable Length Array" Warning?

Jan 27, 2011

As subjected I have this warning message code...

How can I get rid of this warning message?

View 6 Replies View Related

Debian :: Expr Index - Treat Space As String Not Array Separator

Mar 13, 2016

Code: Select allmyusername@mycompname:~$ varCurl="abc def curl: ( xyz asdf"
myusername@mycompname:~$ expr index '$varCurl' "curl: ("
4
myusername@mycompname:~$ expr index "$varCurl" "curl: ("
3
myusername@mycompname:~$ echo $varCurl
abc def curl: ( xyz asdf

How to make sure that space is treated as space and string is not treated as array? (I expect value of 9 or 10, not 3 or 4).

View 2 Replies View Related

Programming :: Book Example Of Own Type Variable Initialization Wont Work?

Nov 8, 2010

Its an example froom a book... and it does not work...

Code:
#include <stdio.h>
int main ( int argc, const char * argv[] ) {

[code]....

View 4 Replies View Related

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 View Related

Programming :: Convert Short Array To Char Array?

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

Programming :: Bash - Read Content Of File To Variable And Use This Variable In For Loop ?

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

Programming :: Make A New Variable With The String From The Old Variable Btut Without Any Plus Sign?

Apr 7, 2010

my script has a variable which comes in the form +00.00 +0.00 -00.00 or -0.00 (the numbers can be any in that form) for any that have a + symbol I need to remove the +, but if it has a - symbol it needs to stay.

i need to make a new variable with the string from the old variable btut without any plus sign. I have tried a lot of different ways with no success, each thing I tried either left the + or removed the entire string. I think this should work but doesn't

foo=+12.40
bar=${foo#+}

View 4 Replies View Related

Programming :: Search Within A Variable And Assign The Results To A New Variable?

Apr 25, 2011

how I can search within a variable and assign the results to a new variable. I'll use the following as an example -

cars="Audi BMW Cadillac Chevy Dodge Ferrari Ford Mercedes"
list=`echo ${cars} | egrep -o '<A?+|<C+'`

with the echo command I get the following output assigned to list -

A
C
C

What I'd like to get for output is -

Audi
Cadillac
Chevy

how I could do this regardless of upper/lower case letters?

View 5 Replies View Related

Programming :: Converting A PHP Array Into An HTML Array?

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

Programming :: Assign Value Of C Variable To Shell Variable?

Apr 28, 2010

included shell script inside c program, and i wanted to assign the value of c variable to shell variable..Can any one please suggest me how to do it?

View 8 Replies View Related

Programming :: Filling 2D Array With 1D Array In C?

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

Programming :: Bash Array Add Function Example Using Indirect Array Reference As Function Argument?

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

Programming :: Assignment To A Variable Variable?

Mar 17, 2011

This loop is part of a bash script which takes multiple arguments.

Code:
for ((i=1;i<=$number;++i)) ; do
offset=$(($i+5))

[code]...

View 3 Replies View Related

Programming :: Could Not Read Symbols - Archive Has No Index

Apr 2, 2010

I am trying to port c & c++ open source code onto embedded target(MIPS).It compiles fine on x86/RH4. When I try embedded platform specific tool chain as follows, I get following error:

I tried different combinations. It did not help. My idea is to port an open source code that works fine on X86/Linux to an embedded target based on MIPS.

View 4 Replies View Related

Programming :: Makefile Index Of List Element?

Apr 5, 2011

So I have been trying for 8 hours to try to get the index of an element from a list in a Makefile. The problem is that after I get the index using all the methods I have tried, the index cant be used in the "word" function:

for instance:
$(OUTPUT2) : INDEX = $(shell echo $(OUTPUT2) | sed -r -e "s/[ ]+/
/g" | grep -n $@ | sed 's/^([0-9]*):.*/1/')

will create a variable INDEX defined specifically for each member of OUTPUT2, so that each output knows its index. Unfortunately, when I pass this $(INDEX) into word, it doesn't work:

$(OUTPUT2) : $(word $(INDEX), $(INPUT1)) $(word $(INDEX), $(INPUT2))
echo $(INAME) $(TMPBASE) $@
and I get the error:
Makefile:16: *** non-numeric first argument to `word' function: 'num'. Stop.

I feel like if I could just convert a string to a Makefile acceptable number this would just work....

View 6 Replies View Related

Programming :: Script To Create Index.html File?

Sep 25, 2010

I need a script that can do this: A script that searches all directories and subdirectories for .html files When a .html file is found it creates a index.html file in that folder. It then edits the index.html file and inserts links to all of the .html files that are in that folder into the body. If no .html files are found, it searches for folders. It then creates a index.html file with links to all of the folders.

View 4 Replies View Related

Programming :: Arrays In The C Programming Language Are Pointers To The First Element Of The Array?

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

Programming :: Python Error - List Index Out Of Range (Web Scrapper)

Feb 18, 2011

Having a bit of an issue with Python while trying to write a script to download every rar file on a webpage. The script successfully downloads any link that doesn't contain any spaces, etc. But when it hits a url like: [URL] (Classical Spelling).rar. It fails...I'm sure this is something simple, but I'm so new to python I'm not sure what to do!

Code:
import urllib2
import os
os.system("curl [URL] -i rar|cut -d '"' -f 2 > temp.out ")
infile =open('temp.out', 'r')
for url in infile:
print url
#url = "[URL]"

#url = target
file_name = url.split('/')[-1]
u = urllib2.urlopen(url)
f = open(file_name, 'w')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192

while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += block_sz
f.write(buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
status = status + chr(8)*(len(status)+1)
print status,
f.close()

View 7 Replies View Related

Programming :: Pass Variable In Mysql Qyery In C Programming?

Dec 4, 2010

i want to pass variable in mysql qyery in c programming

View 1 Replies View Related

Programming :: Array Containing Words In C?

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

Programming :: How To Do An Array Of Characters

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

Programming :: Getting String Value From Array?

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

General :: Grub2 - HOWMANY Variable Does Not Work

Jan 15, 2010

I want try controls how many kernels should be put into the GRUB2 menu on my Ubuntu 9.10 but since GRUB2 the #HOWMANY variable doesn't work. I found this post on the LQ blog about the #HOWMANY variable. I follow these instructions but I have a problem when I execute the last command "update-grub" because my result is this :
Code:
/usr/sbon/grub-mkconfig: 228: GRUB_HOWMANY: not found
I verified my work but I don't understand why it's doesn't work.

View 5 Replies View Related

Programming :: Array Creation At Run-time In C++?

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

Programming :: Convert String To Int Array?

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

Programming :: Represent Alphabet Into A Array?

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

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 View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved