Programming :: Unable To Dynamically Create An Array Of Params For Execv In C

Jan 6, 2011

I haven't programmed in C for a while, so I am trying to remember certain aspects of syntax. I have a program that will fork and exec other programs. Those programs will be specified on the command line as follows:

./main "prog1 arg arg ..." "prog2 arg arg ..."

Here is the main snippet:

int countChar(char* s, char c)
{ int cnt = 0;
int len = strlen(s);
for(int i = 0; i < len; i++)

[code]....

The highlighted line is the problem. I get this error:

dualstarter.cpp:58: error: initializer fails to determine size of 'params'.

Right now I am thinking of creating an array with the specified size and simply copying the required string into it, but it just seems like there is an easier way.

View 9 Replies


ADVERTISEMENT

Programming :: Bash - Read The Array Dynamically?

Sep 24, 2010

Code:

test=(1 2 3 4 5)
for car in ${test[@]}
do
echo "Element : $car"

[code]....

if variable $car equals 1, new element is added "6" to an array. But i don't know why when i am printing all elements of this array (echo "Element : $car") this element ("6") is not mentioned, but if i make a command which check an amount of contained elements by array it will be 6 elements.

View 14 Replies View Related

Programming :: How To Call Array Dynamically Into Script?

Jul 20, 2011

I have a script which takes an array as an input to the file.ex: test.ksh -l <array_value>

Every time I dont get the same array name.EX: test.ksh -l x ; where x="a b"test.ksh -l y ; where y="c d"

I store the value I get in l in varaible myLvalue.Now indise my Script I want to run a for loop for thevalue I get in -l.If I write the for loop as below. I'm getting value x.However I'm expecting the loop to run for a and b.

View 5 Replies View Related

Programming :: Local Dynamically Allocated Array In Fortran?

Oct 19, 2009

I (my friend) have a fortran program with the code along the following lines:

Code:

SUBROUTINE NY
REAL, DIMENSION(4000,4000) :: a, b, c
...
RETURN
END SUBROUTINE PARAMETERS

The problem is that the huge matrices are retained in memory even after the subroutine ends. Is there an easy way to declare the arrays in a sort of dynamic way, like they were in the following C example?

Code:

void ny(void) {
double a[4000,4000];
...
}

I mean in the C example the memory is released as soon ny() exits.

View 5 Replies View Related

Programming :: Read Any Given Maze.txt Into An Internal Dynamically Allocated Array Of Strings?

Apr 26, 2011

I am looking for an easy way to convert any given maze.txt of any size to a internal array of strings(dynamically allocated). Important is that dimensions of the maze (row, col) shouldn't be written by the user instead they have to be somehow read from the file. This is not my homework assignment! It is a small part of a project that i never dealt with. I never read files to C string.... I made it for specific maze dimensions, but want it to work with any given .txt file.

View 9 Replies View Related

Programming :: Python: Dynamically Create A List Within A Dictionary?

Jul 9, 2011

how to dynamically create a list within a dictionary using Python.

Code:
dates = defaultdict(int)
array = []
...
dates[m.group(3)] = array.append(date)
dates[m.group(3)] = [array.append(date)]
dates[m.group(3)].append(date)

None of the above works and I've tried everything I can think of.

View 3 Replies View Related

Programming :: Jquery To Dynamically Create Cookies Using The Jquery Cookie Plugin?

Jul 27, 2011

I am learning jquery and I think for the most part I have the basics down. One of the things that I am attempting to do is to create cookies using the jquery cookie plugin. The idea is that I want to replace as much of the javascript in my code as possible with jquery to see the difficulties in doing it one way or the other.

As easy as it seems to be able to create a cookie using the plugin I have not been able to do some successfully and the only thing that I can think of is the way that I am submitting my parameters is not correct. So with that, here is is my code:

[Code]...

View 5 Replies View Related

Programming :: Sort Of Execv Command Needed?

Jul 2, 2010

I have a problem, I need to launch another binary from my application, but I need to get the control back once the other binary is initialized. fork/exec doesn't seem to give anything on that side using pthreads I'm able to wait until the new thread exits, but that's not what I want at the moment I'm using popen, but it doesn't seem to do the job right...

View 14 Replies View Related

Programming :: Create A Small Array Of 3x3 Arrays?

Jul 12, 2009

I'm trying to figure how to create an small array of 3x3 arrays such I can do

Code:

SUM1(i) = SUM1(i) + SUM2

where i goes from 1 to 8 and SUM2 is a 3x3 array.

View 2 Replies View Related

Programming :: Create An Array That Will Allow To Print A List After Selection?

Oct 18, 2010

I am trying to create an array that will allow me to print a list after selection such as:

1) Location A
2) Location B
3) Location C

Would you like to print selected locations? Print I have no idea how to approach this problem and don't know whether Perl, Bash or shell script would be the most useful in this particular situation.

View 5 Replies View Related

Programming :: Disallow File Access For Child Process With Execv?

Mar 8, 2011

I need to disable file access (fopen, freopen, open etc) for application which is running under chroot jail and with restrictions (rlimit) via execv. Before that I redirected stdin/out to files within jail. I tried this:

Code:
// Redirect stdin/stdout to files
int fd = open (file_input, O_RDONLY);
if (fd < 0)
fatal_error ("input open failed!");

[Code].....

View 6 Replies View Related

General :: Dynamically Create/delete Device Nodes By Driver?

Apr 15, 2010

I'm a starter here in linux, I have written a driver code and in that, I register my character devices by passing 0 for the major number.

To set up I used to use mknod command from terminal to create node,

Is there any method to create node dynamically from driver code during initialization and delete them at cleanup time?

View 1 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 :: Dynamically Loading Libraries In GNU?

Oct 22, 2010

This post isn't really asking for a tutorial, but rather asking for some ideas. I've come up with a few ideas, but they seem cumbersome and unnecessary, so I was wondering if someone with more experience than me could out. Also, my explanations suck, but I'll try to do my best. So say I have an executable called X. At some point during its execution, X loads and uses (using dlopen and dlsym) a library called Y. In Y, there a bunch of functions that call the function called, for example, void *special_malloc (size_t). These functions come from another linked library (linked during compilation) called Z. Problem is, special_malloc contains some static variables within its scope, and when those variables are reset midway through a program, an invalid free occurs (special_malloc uses garbage collection). Now, what I want to happen is that whenever lib Z calls special_malloc, it instead calls the special_malloc defined in the executable X, so that these static variables are retained. Keep in mind that I have control of the Z library, meaning I can edit the source to fit my needs.

View 2 Replies View Related

Programming :: Java : Use Dynamically Loaded Classes?

May 15, 2010

I'm new to Java.
I'm trying to use some dynamically loaded classes in my application.
The application doesn't know those classes , Just it try to load a class by name that its name came from input.
It doesn't know class (So I can't use casting) but just needs to call some methods of that class (every class should have that methods).
I thought about interfaces but I don't know how.
How can I call those methods?

View 1 Replies View Related

Programming :: Link One Library Statically Others Dynamically - Gcc - G++

Jul 6, 2011

I would like to make gcc to link one lib (pthread in the example) statically, and the rest dynamically.

(See the example .c file at the end of this post.)

compiles fine, but every lib is linked dynamically.


Now every lib is linked statically

Not a dynamic executable

I would like to link the libpthread statically and the rest dynamically. Is it possible?

[url]says if I give the full path to the .a lib then it will be linked statically:

So for me it does not work.

On other sites I found that I should use -Wl,-Bstatic -lpthread -Wl,-Bdynamic, but it also doesn't work:

So, how can I do that?

Machine: Linux 2.6.16.60-0.27-bigsmp #1 SMP Mon Jul 28 13:06:32 UTC 2008 i686 i686 i386 GNU/Linux SLED 10

As an example I used a little demo program from [url]

Here is the code:

View 4 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 :: Dynamically Supply Input To Netcat In A Script?

Mar 5, 2010

I am trying to write an irc bot to run interactive fiction games in a channel. I am connecting to the channel using nc. I'm having a hell of a time trying to supply input stdin for nc after the connection is established. Here's what's going on. I've got lines of plain text in a file with the irc commands required to identify the bot's ID and join the channel. I can connect easily using any of the following commands

cat inputfile | nc irc.servername.org 6667 -i 1
nc irc.servername.org 6667 -i 1 < inputfile
Named_Pipe | nc irc.servername.org 6667 -i 1
cat inputfile > Named_Pipe

With the first two commands nc connects, reads the file with some time between each line allowing the irc server to respond, bringing me into the channel. It then begins to receive stdin from the command line allowing me to do things like "privmsg #channelname :Hello World!!!" sending messages to the room. This is not the desired behavior. I require nc to take additional stdin from the inputfile if I cat additional text to the end of it.

The last set of commands using the named pipe seem like it does the same, but it doesn't actually send anything to the room, which indicates to me that perhaps nc is continuing to take stdin from the named pipe (this is the desired behavior) rather than dropping to the console for stdin. If I try to cat more plain text data to the end of the named pipe, however, either with something like "echo 'privmsg #channelname :Hello World!!!' > Named_Pipe" (or >> instead of >) or with a filename in place of the "echo" command the whole command simply seems to hang until I press ctrl-C.

I don't understand what I'm doing wrong. With anonymous and named pipes, and with redirection, the problem seems to be the same. nc seems to take it's stdin from the file until it hits the end of file, at which point I can no longer introduce new lines of plain text as stdin for the running nc process.

View 4 Replies View Related

Programming :: Get Path Of One Library To Link It Dynamically In Program?

Apr 28, 2010

I'd like to get path of one library to link it dynamically in my program. Probobly the best way would be to add macro to my configure.ac file.

View 2 Replies View Related

Programming :: Wrote A Driver That Scans On Startup Dynamically For Available EEPROM's On A Certain IC Bus?

Jul 28, 2011

I wrote a driver that scans on startup dynamically for available EEPROM's on a certain IC bus. For each EEPROM a new character device is created in /dev like:

/dev/bus0eepromA0
/dev/bus0eepromA1
/dev/bus0eepromA2 ...

[code]....

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

Fedora :: Postfix 2.7.0 Ignoring Main.cf Params

Aug 31, 2010

I've recently upgraded my home server from fc5 to fc13 which means installing the latest version of postfix (identified as 2.7.0 in the maillog). It is used to send mail from cron jobs and logwatch to a local mailbox (aliased) and my googlemail account so I can monitor when away from home. I finally got it working, but had to pull a trick that I feel bad about--it feels very hacky, and does not survive a reboot.The problem is no matter what I do, this version of Postfix ignores the settings for "masquerade_domains", "myhostname" and "mydomain" in main.cf, using instead whatever 127.0.0.1 (or :::1) is set to in /etc/hosts!!

To send mail to Internet locations, the "from" needs to be a valid domain. In an earlier version of Postfix (2.6.x) I just fudged this to a domain I own (that is parked) in main.cf using "masquerade_domains". Now I have to insert it in /etc/hosts instead of "localhost". I can't find anyone on the web who seems to be having this problem. Postfix is definitely reading main.cf as it is obviously picking up other setings such as debug_peer_level and proxy_interfaces.

As I said, it works, but I don't like my solution and /etc/hosts gets rewritten to ":::1 localhost6.localdomain6" when the system is rebooted, meaning I have to edit it to get Postfix working again as sendmail rejects "localhost6.localdomain6" as not found:

[Code]....

View 4 Replies View Related

Programming :: Save / Load Data Segment Of Dynamically Loaded Shared Object Library?

Aug 25, 2010

Our application uses a dynamically loaded shared object library (codec library) to compress and decompress audio streams.

There happens to be several static and global variables in this shared object library. Hence it is not possible to process two interleaved unrelated media streams using this shared object codec library because each stream corrupts/changes the contents of these static/global variables.

Is there a way through which a context save (save contents of data segment of shared object) and a context load (load previously saved contents of data segment of shared object)operation can be performed on the shared object library. This way the context for each media stream can be saved and loaded before and after processing the "other" media stream respectively.

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

Ubuntu :: Create A Raid0 Array Of Drives?

Feb 20, 2011

Just got 3 extra drives for my machine.

2x160Gb sata
1x 165Gb sata

How do i create a raid0 array of these drives? On each drive i have got a partition whose size is 160GB and formatted to type fd (Raid Autodetect) i have tried the following:

Code:
mdadm --create /dev/md0 --level=0 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sda1
mkfs.ext4 /dev/md0
mount /dev/md0 /media/raid
but for some reason it doesnt work.

[Code]...

View 5 Replies View Related

General :: Create RAID1 Array With Given/fix HD Labels?

Aug 19, 2010

I have two HDs (let's say sda and sdb). Both are the same size and have the same partitions already (sda1/sda2/sda3 and sdb1/sdb2/sdb3). Basically they are ready to make a RAID1 array.

Writing with new udev rules, I could create and give fix HD labels with /sbin/scsi_id.

Example: For sdb1 I have a fix device name created under /dev as hd2_boot1, for sdb2 I have /dev/hd2_boot2 and finally for sdb3 I have created the device /dev/hd2_boot3.

With using the command "mdadm --create /dev/md0 --level=1 ....", I could create a RAID array.

But, when I check the status one of the RAID devices, like with the command "mdadm --detail /dev/md2", it still shows me as part of the RAID array the sdb* devices, not the hd2_boot* devices. Something like this:

I would like to see basically as member or the RAID array always the /dev/hd2_boot3 not the /dev/sdb3 (like above), is this possible?

Bottom line, I would like to keep the order of the RAID arrays depending their scsi ids, not depending their scsi numberings which is given by the kernel, since the scsi numberings (sda, sdb, sdc and etc.) can change depending the physical connection.

View 2 Replies View Related

CentOS 5 :: Raid 1 - Need To Create Array On Every Restart

Mar 10, 2010

I have a raid 1 array which I did setup on a Centos box. I can configure the array fine the problem is every time is restart my machine I can no longer see the array and have to go create it all over again. I tried doing a few searches on it but have came up with nothing so far.

View 19 Replies View Related

Fedora :: RAID 1 - How To Create New Array Without Losing Data

Jan 1, 2010

I have a software RAID array using mdraid that consists of two 1.5TB drives that I use for storage, the array is mounted at /Storage. I am running out of space in the array so I ordered two more 1.5TB drives to create a 4 drive RAID 1+0 array which will be 3TB big. My question is how do I create the new array and not lose any data?

The drives and partitions are sdc1, sdd1, and soon to be sde1, sdf1. I currently have 4 RAID arrays (md0,md1,md2,md3). I think I can create the RAID 1+0 array with the two new drives, copy the data from my current array to the new one, remove the old array, then add the two original drives to the new array. But I wanted to ask on here first to make sure my data doesn't go poof.

View 1 Replies View Related

Server :: Mdadm Create,, Raid Array Is Not Clean?

Nov 16, 2009

mdadm --create /dev/md1 --level=1 --raid-disks=2 missing /dev/sdb1and I getmd1: raid array is not clean -- starting background reconstructionWhy is it not clean?Should I be worried?The HD is not new it has been used in before in a raid array but has beenrepartitionated.

View 2 Replies View Related







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