2 days ago I’ve installed linux on my machine (1st time in my life :P) and now I’m tryin to write a char into a file. For some reason, it’s not working… Here’s my code.
#include <stdio.h>
#include <fcntl.h>
int main (int xd, char *tab[]) {
char *path1 = tab[1];
int filee = open(path1, O_WRONLY | O_CREAT| O_TRUNC, 0777);
write(filee, 'x', sizeof(char));
close(filee);
return 0;
}
What could be wrong in this little piece of code? I’ve checked and function ‘write’ returns -1, even though function ‘open’ creates the file when it doesnt exist.
Thanks.
writetakes a pointer to a memory buffer as the second argument, but you pass it anintYou should try something along the lines of