First, the warning about %s in conjunction with strerror() is because you haven't included string.h. The strerror() function returns a pointer to a string, and if you don't include string.h the compiler assumes that it returns int, and thus issues the warning about the mismatch with %s. Include string.h and change the %d to a %s. It has nothing to do with the type of errno.
You also should include sys/types.h and sys/wait.h.
Your initialisation of a, b and c is missing curly braces. To be correct, you need something like this for a and b:
For c you need
Those are all to correct compiler warnings. The real problem is in your writing from the child. You are converting each value to string and placing it in str with a terminating NULL character. That is correct. However, you are writing the entire buffer, including the characters past the NULL to the parent. You need to write just the values, and the associated trailing blank, to the parent. To do this you need to capture the length of the string created by sprintf() and use that as the number of characters to write to the pipe. For completeness, I would also write a final NULL to the pipe after all of the values. Something like the code segment below:
Yes, the way you changed it works perfectly thanks!
But, i will connect this code with another part which read the arrays from a .txt file.
I have already done the reading part, but i think that this part :
will be a problem because is "manual". Is there a way i can use this part for different types of arrays. For example if my c wasnt with 4 columns. I am thinking something like puting the sscanf() into a for(), but my tries dont work....
Hi
$ a=10 ; b=2
$ expr $a + $b
12
$ expr $a - $b
8
$ expr $a / $b
5
$ expr $a * $b
expr: syntax error
Any idean why I am getting this error only when multiplying two numbers. Whats the exact syntax?
Thanks a lot to all in advance
CSaha (5 Replies)
Is there a way that i can get something like this to work:
Number=`expr 80 \* 10.69`
i.e. To multiply an integer by a decimal or a decimal by a decimal etc...?
thanks (10 Replies)
Im very new to programming. But I would like to write a script which extracts and multiply values from 2 txt and output as a new file. Can someone please teach me how to write it? Thank you so much
for example
File A File B
1 34 1 2
2 13 2 2
3 8 3 3
File C output
1 68
2... (2 Replies)
if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Hi, this is my code.It's simple : there are 2 2D arrays and the multiplied to C.
#include<stdio.h>
#include<sys/shm.h>
#include<sys/stat.h>
#include<stdlib.h>
main()
{
int *A; //A
int *B; //B
int *C; //C
int i,j,x,k,d;
int id;
... (17 Replies)
hello,
I'm writing a php script in fedora to run with a csv file. I want the script to read column 4 and multiply each single line in the column by 1000, how would that script look? I've written one script but it's obviously incorrect because it will not execute the command.
here is my... (4 Replies)
I am trying to take all the elements of an array and multiply them by 2, and then copy them to a new array. Here is what I have
i=0
for true in DMGLIST
do
let DMGSIZES2="${DMGSIZES}"*2
let i++
done
unset i
echo ${DMGSIZES2}
It does the calculation correctly for the first element,... (7 Replies)
I have 2 files, that look like this:
ID SNP1 SNP2 SNP3 SNP4
A1 1 2 0 2
A2 2 0 1 1
A3 0 2 NA 1
A4 1 1 0 2
and this:
SNP score
SNP1 0.5
SNP2 0.7
SNP3 0.8
SNP4 0.2
Basically, all of the SNP-values are 0,1, 2 or NA, and they each have a score, listed in the second file. The total... (5 Replies)
Hi Experts,
Please help with the following.
I have 3 columns in File 1 , variables with values nested within groups.
File 1
gr1 var1 a
gr1 var2 b
gr1 var3 a
gr1 var4 c
gr2 var1 a
gr2 var2 a
gr2 var4 c
gr3 var1 b
gr3 var3 b
gr3 var4 a
gr3 var5 a (3 Replies)
I am trying to remove the last letter in a file and then multiply each line (which contained this letter) by 500. This is what I have:
1499998A
1222222A
1325804A
1254556
1235
9998
777
cat /tmp/listzz |gawk '{print $4}'|gawk '{gsub(//, ""); print } This removes the A... (1 Reply)