Exercise 3 - Reading from urandom using C
This commit is contained in:
parent
7013102385
commit
b1e1727f28
22
excercise3/exercise3b.c
Normal file
22
excercise3/exercise3b.c
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main (int argc , char** argv ){
|
||||||
|
|
||||||
|
// Open file for reading
|
||||||
|
// We are opening a device file for reading ,
|
||||||
|
// which is like reading from a file but the file is not necessarily an actual file on disk.
|
||||||
|
// instead it could be some sort of external device or a simple piece of software returning bytes to us
|
||||||
|
FILE* fp = fopen("/dev/urandom", "r");
|
||||||
|
if( !fp){
|
||||||
|
perror("File opening failed!");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( 1 ){
|
||||||
|
|
||||||
|
printf("Read 0x%x from /dev/urandom\n", fgetc(fp));
|
||||||
|
int goAgain ;
|
||||||
|
scanf("%d", &goAgain);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user