Exercise 3 - Reading from urandom using C

master
Nigel Barink 2020-10-17 22:07:39 +02:00
parent 7013102385
commit b1e1727f28
1 changed files with 22 additions and 0 deletions

22
excercise3/exercise3b.c Normal file
View 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);
}
}