程序代写案例-NANOS 10000000

*) how to use nanosleep
#define TEN_MILLIS_IN_NANOS 10000000
struct timespec t;
t.tv_sec = 0;
t.tv_nsec = rand()%(TEN_MILLIS_IN_NANOS+1);
nanosleep(&t, NULL);
*) how to read a char and offset from/to a file
if (!(file_in = fopen(infile, "r"))) {
error("could not open input file for reading");
}
...
result.offset = ftell(file_in); /* get position of byte in file */
result.byte = fgetc(file_in); /* read byte from file */
...
fclose(infile)
--------------------------------------------------------
if (!(file_out = fopen(outfile, "w"))) {
error("could not open output file for writing");
}
...
if (fseek(file_out, d.offset, SEEK_SET) == -1) {
fprintf(stderr, "error setting output file position to %u\n",
(unsigned int) d.offset);
exit(-1);
}
if (fputc(d.byte, file_out) == EOF) {
fprintf(stderr, "error writing byte %d to output file\n", d.byte);
exit(-1);
}
...
fclose(infile)
*) When does the program finish?

欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468