If the file does not exists, open(name,'r+') will fail.
You can use open(name, 'w'), which creates the file if the file does not exist, but it will truncate the existing file.
Alternatively, you can use open(name, 'a'); this will create the file if the file does not exist, but will not truncate the existing file.