954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Random numbers (finding odd and even numbers)

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.

#include <stdlib.h>
#include <stdio.h>

int main(void)
{
    int A;
    srand(time(0));
    for (A = 0; A < 50; ++A) {
       int number;

       number = rand();
       printf("%d\n");

  }
  return 0;
}

i create first part of the program i also know how to find odd and even numbers

if ( x % 2 == 0 ) { //even
 
} else { /odd
 
}

i know that i must insert "fd = open("blabla",O_RDWR|O_CREAT,0)" after "if" but my knowlodge isnt enogh :(
thanks

satanix
Newbie Poster
2 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

don't use open(), instead use fopen() because FILE* and associated functions are much easier to use.

Here is a file i/o tutorial

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

satanix
Newbie Poster
2 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You