Hey very simple problem. I've been searching the site to see if I did anything wrong and I had to fail because I still get the wrong results (semantic error). Problem #1: Every time I use fopen with the "w" (or write) mode the file with whatever name given is not created which brings us to the second problem. Problem #2: Correct me if I am wrong (syntax might of changed due to updates), but as I know according to Dave Mark's "Learn C on the Mac" he specifies as filename paths as the following:
All of the following are the same:
Location from root: /Users/davemark/test/myFile.text
Location from source code file: ./myFile.text meaning myFile.text is in the same folder as the source code file
or: ../myFile.text meaning myFile.text is in the parent directory from the source code file
Location from home directory: ~/test/myFile.text
I think that problem number #1 is a result of problem #2 and it is because every time I use fopen I specify the filename path from the source code file. I don't want to use the location from root every time so heres my code, what am I doing wrong?:
#include <stdio.h>
#include <string.h>
#define kFilenameSize 256
int main(int argc,char ** argv)
{
char filename[kFilenameSize]="The file is named qwerty";
FILE *userfile = 0;
userfile = fopen("./qwerty.text", "w");
fputs(filename, userfile);
fclose(userfile);
}