Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text file... then average the numbers in the text file and print the average.
I'm not entirely sure I'm doing this correctly (This is my first Perl program!) so if there are additional mistakes that anyone sees that will trip me up after I get this problem fixed, I'd more than welcome the feedback.
The error I'm getting with the command 'perl -w myperl':
Quote:
Can't exec "myprog": No such file or directory at myperl line 15.
The error I get with the command 'perl -d myperl':
Quote:
Can't locate perl5db.pl in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.0 /usr/local/share/perl/5.10.0 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .).
BEGIN failed--compilation aborted.
When I try to just type 'perl myperl', I get a 0 printed to the screen and nothing is in datafile.txt.
My C Program (called 'myproc.c', when compiled is 'myprog'):
My Perl program (called 'myperl'):
School info: Arkansas State Univerity, Jonesboro, AR, Dr. Hai Jiang, CS 4-5223
---------- Post updated 02-20-11 at 12:35 PM ---------- Previous update was 02-19-11 at 06:03 PM ----------
I actually got this figured out with the help of a friend, so here's that answer if it helps anyone:
FOR THE PERL PART
When opening files for input and output in Perl, do it like this:
output-
input-
To run the C program within your perl program: FOR THE C PART
I had a problem within my initrand function which was causing all the output numbers to be the same. This is caused by the fact that the srand() function for seeding is by the second, which doesn't work when trying to run a program multiple times per second. This is a problem I'm actually still trying to work on a little, but that's a good first step towards solving your own problem.
I was trying to REdefine RAND_MAX, so that was renamed to RANDINT_MAX.
When casting an int, use parentheses:
return (int) (/*stuff*/);
Just getting into the Unix command line programming and am unable to run any program I write. I am using a Makefile and the source is compiling but when I enter the name of the output file I get back:
bash: lab01exe.out: command not found
I'm sure I am just dooing something simple... (2 Replies)
I am confused about how to use a .exe file in unix along with a compiled C++ program. I've been using emacs and I compiled with g++, but I have no idea how that relates to use with a .exe. (1 Reply)
Hello All,
I have coded a C program which looks something like below... (program name: test.c)
#include<stdio.h>
main()
{
int dist,dm,dcm;
printf(" Enter the distance between 2 cities in KM : ");
scanf("%d",&dist);
dm=dist*1000;
dcm=dist*10;
printf("Distance between 2 cities in... (6 Replies)
On bash I run precompiled c Program as follows:
./create_cust 1 10000 US S > us_cust.csv
create_cust is a c program and requires 4 parameters.
I am redirecting the output of this program to csv file
I need to run this same program in perl
I am aware of exec command though not... (7 Replies)
I am trying to make an application which works on unix to work on linux. I already tried copying the binary files and start it up but I am getting an error stating "Cannot execute binary file". Then I tried to recompile but i am getting an error whenever I tried to recompile. I am getting the... (1 Reply)
Hi,
We upgraded our servers from solaris 9 to 10. We recompiled all the Pro*C programs with the new oracle version as well. Oracle is 11g. We are facing core dump with the below error for certain executions. But when we are placing new statements between the error fucntion we get junk values to... (1 Reply)
I have put some yellow color codes and works well.
I call the funstion using
print_usage(stderr, 0);
I would like to know if there is any way, to store the ansi color codes in variables and then call them inside fprintf.
Or have a format followed by the strings I want to output.
... (5 Replies)
Will a program compiled in ubuntu 14.04 execute in Centos 7? That is to say a tarball or zip is downloaded from github and extracted, compiled, and make is all done in ubuntu 14.04, can I mv the program from ubuntu 14.04 to Centos 7, add it to path in Centos 7. And run it? Thank you :) (3 Replies)
I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade.
I have:
if ( $response =~ m/^/ ) {
$user_wants_to_quit... (1 Reply)