Random numbers (finding odd and even numbers)

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2008
Posts: 2
Reputation: satanix is an unknown quantity at this point 
Solved Threads: 0
satanix satanix is offline Offline
Newbie Poster

Random numbers (finding odd and even numbers)

 
0
  #1
May 12th, 2008
hello i have got little problem
create a c program which starts with 3 processes the first proccess generates 50 random numbers and writes them inti common memory. the second proccess reads them and whrites the even numbers in file A,the odd numbers in file B.
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int main(void)
  5. {
  6. int A;
  7. srand(time(0));
  8. for (A = 0; A < 50; ++A) {
  9. int number;
  10.  
  11. number = rand();
  12. printf("%d\n");
  13.  
  14. }
  15. return 0;
  16. }
i create first part of the program i also know how to find odd and even numbers
  1. if ( x % 2 == 0 ) { //even
  2.  
  3. } else { /odd
  4.  
  5. }
i know that i must insert "fd = open("blabla",O_RDWR|O_CREAT,0)" after "if" but my knowlodge isnt enogh
thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,620
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1493
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Random numbers (finding odd and even numbers)

 
0
  #2
May 12th, 2008
don't use open(), instead use fopen() because FILE* and associated functions are much easier to use.

Here is a file i/o tutorial
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 2
Reputation: satanix is an unknown quantity at this point 
Solved Threads: 0
satanix satanix is offline Offline
Newbie Poster

Re: Random numbers (finding odd and even numbers)

 
0
  #3
May 13th, 2008
thanks for answer and tutarial page i read all of them fopen seems better then open.At the code which i wrote it finds 50random numbers but i dont know how to find old or even numbers and write them to 2 different file.
thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC