How to create a file in Ruby

Use: File.open(“out.txt”, [your-option-string]) {|f| f.write(“write your stuff here”) } where your options are: r – Read only. The file must exist. w – Create an empty file for writing. a – Append to a file.The file is created if it does not exist. r+ – Open a file for update both reading and writing. The … Read more

How to know what the ‘errno’ means?

You can use strerror() to get a human-readable string for the error number. This is the same string printed by perror() but it’s useful if you’re formatting the error message for something other than standard error output. For example: #include <errno.h> #include <string.h> /* … */ if(read(fd, buf, 1)==-1) { printf(“Oh dear, something went wrong … Read more