By using the write function (and open) below, you are actually not using standard C functions, though they will be widely implemented.Originally Posted by The_Lone_Wolf
Anyway, your code has issues:
- if you want to do 5 zeroes, why are you trying to write the value of "scores"?
- Why is it in the for loop? Try:
- I assume you want to create a text file, and have the scores human readable, in which case you could either use fprintf, or use write() to send a string that's been built with something like snprintf().Code:for (i = 0; i < 5; i++)
Standard C has no concept of inodes. Look up the posix functions stat and fstat.also how do i do the i node number i have no idea about this?
All your code here is within the if (argc != 2) block, so if there is not 1 parameter, it will print the usage and exit. If there is one parameter, it will skip the whole code you pasted and go onto whatever else there is.Code:#include<stdio.h> #include<string.h> #include<errno.h> int main (int argc, char *argv[]) int scores; if (argc !=2) { printf("Usage: %s scores\n", argv[0]); exit(1); fd = open("scorefile", 0_RDWR | 0_CREAT, 0600); if (fd<0) { perror("cannot open file score"); exit(2);