ㄧ计: fabs : 疊翴计荡癸 ノ 猭: double fabs(double x); 祘ㄒ: #include <stdio.h> #include <math.h>
int main(void) { float number = -1234.0;
printf("number: %f absolute value: %f\n", number, fabs(number)); return 0; }
ㄧ计: farcalloc : 眖环帮刺いビ叫丁 ノ 猭: void far *farcalloc(unsigned long units, unsigned ling unitsz); 祘ㄒ: #include <stdio.h> #include <alloc.h> #include <string.h> #include <dos.h>
int main(void) { char far *fptr; char *str = "Hello";
/* allocate memory for the far pointer */ fptr = farcalloc(10, sizeof(char));
/* copy "Hello" into allocated memory */ /* Note: movedata is used because you might be in a small data model, in which case a normal string copy routine can not be used since it assumes the pointer size is near. */ movedata(FP_SEG(str), FP_OFF(str), FP_SEG(fptr), FP_OFF(fptr), strlen(str));
/* display string (note the F modifier) */ printf("Far string is: %Fs\n", fptr);
/* free the memory */ farfree(fptr);
return 0; }
ㄧ计: farcoreleft : 环帮いゼノ纗跋 ノ 猭: long farcoreleft(void); 祘ㄒ:
#include <stdio.h> #include <alloc.h>
int main(void) { printf("The difference between the\ highest allocated block in the\ far\n"); printf("heap and the top of the far heap\ is: %lu bytes\n", farcoreleft());
return 0; }
ㄧ计: farfree : 眖环帮い睦遏 ノ 猭: void farfree(void); 祘ㄒ:
#include <stdio.h> #include <alloc.h> #include <string.h> #include <dos.h>
int main(void) { char far *fptr; char *str = "Hello";
/* allocate memory for the far pointer */ fptr = farcalloc(10, sizeof(char));
/* copy "Hello" into allocated memory */ /* Note: movedata is used because you might be in a small data model, in which case a normal string copy routine can't be used since it assumes the pointer size is near. */ movedata(FP_SEG(str), FP_OFF(str), FP_SEG(fptr), FP_OFF(fptr), strlen(str));
/* display string (note the F modifier) */ printf("Far string is: %Fs\n", fptr);
/* free the memory */ farfree(fptr);
return 0; }
ㄧ计: farmalloc : 眖环帮いだ皌纗遏 ノ 猭: void far *farmalloc(unsigned long size); 祘ㄒ:
#include <stdio.h> #include <alloc.h> #include <string.h> #include <dos.h>
int main(void) { char far *fptr; char *str = "Hello";
/* allocate memory for the far pointer */ fptr = farmalloc(10);
/* copy "Hello" into allocated memory */ /* Note: movedata is used because we might be in a small data model, in which case a normal string copy routine can not be used since it assumes the pointer size is near. */ movedata(FP_SEG(str), FP_OFF(str), FP_SEG(fptr), FP_OFF(fptr), strlen(str));
/* display string (note the F modifier) */ printf("Far string is: %Fs\n", fptr);
/* free the memory */ farfree(fptr);
return 0; }
ㄧ计: farrealloc : 秸俱环帮いだ皌遏 ノ 猭: void far *farrealloc(void far *block, unsigned long newsize); 祘ㄒ:
#include <stdio.h> #include <alloc.h>
int main(void) { char far *fptr;
fptr = farmalloc(10); printf("First address: %Fp\n", fptr); fptr = farrealloc(fptr,20); printf("New address : %Fp\n", fptr); farfree(fptr); return 0; }
ㄧ计: fclose : 闽超瑈 ノ 猭: int fclose(FILE *stream); 祘ㄒ:
#include <string.h> #include <stdio.h>
int main(void) { FILE *fp; char buf[11] = "0123456789";
/* create a file containing 10 bytes */ fp = fopen("DUMMY.FIL", "w"); fwrite(&buf, strlen(buf), 1, fp);
/* close the file */ fclose(fp); return 0; }
ㄧ计: fcloseall : 闽超ゴ秨瑈 ノ 猭: int fcloseall(void); 祘ㄒ:
#include <stdio.h>
int main(void) { int streams_closed;
/* open two streams */ fopen("DUMMY.ONE", "w"); fopen("DUMMY.TWO", "w");
/* close the open streams */ streams_closed = fcloseall();
if (streams_closed == EOF) /* issue an error message */ perror("Error"); else /* print result of fcloseall() function */ printf("%d streams were closed.\n", streams_closed);
return 0; }
ㄧ计: fcvt : р疊翴计锣传才﹃ ノ 猭: char *fcvt(double value, int ndigit, int *decpt, int *sign); 祘ㄒ:
#include <stdlib.h> #include <stdio.h> #include <conio.h>
int main(void) { char *string; double value; int dec, sign; int ndig = 10;
clrscr(); value = 9.876; string = ecvt(value, ndig, &dec, &sign); printf("string = %s dec = %d \ sign = %d\n", string, dec, sign);
value = -123.45; ndig= 15; string = ecvt(value,ndig,&dec,&sign); printf("string = %s dec = %d sign = %d\n", string, dec, sign);
value = 0.6789e5; /* scientific notation */ ndig = 5; string = ecvt(value,ndig,&dec,&sign); printf("string = %s dec = %d\ sign = %d\n", string, dec, sign);
return 0; }
ㄧ计: fdopen : р瑈籔ゅン琡钡 ノ 猭: FILE *fdopen(int handle, char *type); 祘ㄒ:
#include <sys\stat.h> #include <stdio.h> #include <fcntl.h> #include <io.h>
int main(void) { int handle; FILE *stream;
/* open a file */ handle = open("DUMMY.FIL", O_CREAT, S_IREAD | S_IWRITE);
/* now turn the handle into a stream */ stream = fdopen(handle, "w");
if (stream == NULL) printf("fdopen failed\n"); else { fprintf(stream, "Hello world\n"); fclose(stream); } return 0; }
ㄧ计: feof : 浪代瑈ゅン挡才 ノ 猭: int feof(FILE *stream); 祘ㄒ:
#include <stdio.h>
int main(void) { FILE *stream;
/* open a file for reading */ stream = fopen("DUMMY.FIL", "r");
/* read a character from the file */ fgetc(stream);
/* check for EOF */ if (feof(stream)) printf("We have reached end-of-file\n");
/* close the file */ fclose(stream); return 0; }
ㄧ计: ferror : 浪代瑈岿粇 ノ 猭: int ferror(FILE *stream); 祘ㄒ:
#include <stdio.h>
int main(void) { FILE *stream;
/* open a file for writing */ stream = fopen("DUMMY.FIL", "w");
/* force an error condition by attempting to read */ (void) getc(stream);
if (ferror(stream)) /* test for an error on the stream */ { /* display an error message */ printf("Error reading from DUMMY.FIL\n");
/* reset the error and EOF indicators */ clearerr(stream); }
fclose(stream); return 0; }
ㄧ计: fflush : 睲埃瑈 ノ 猭: int fflush(FILE *stream); 祘ㄒ:
#include <string.h> #include <stdio.h> #include <conio.h> #include <io.h>
void flush(FILE *stream);
int main(void) { FILE *stream; char msg[] = "This is a test";
/* create a file */ stream = fopen("DUMMY.FIL", "w");
/* write some data to the file */ fwrite(msg, strlen(msg), 1, stream);
clrscr(); printf("Press any key to flush\ DUMMY.FIL:"); getch();
/* flush the data to DUMMY.FIL without\ closing it */ flush(stream);
printf("\nFile was flushed, Press any key\ to quit:"); getch(); return 0; }
void flush(FILE *stream) { int duphandle;
/* flush the stream's internal buffer */ fflush(stream);
/* make a duplicate file handle */ duphandle = dup(fileno(stream));
/* close the duplicate handle to flush\ the DOS buffer */ close(duphandle); }
ㄧ计: fgetc : 眖瑈い弄才 ノ 猭: int fgetc(FILE *stream); 祘ㄒ:
#include <string.h> #include <stdio.h> #include <conio.h>
int main(void) { FILE *stream; char string[] = "This is a test"; char ch;
/* open a file for update */ stream = fopen("DUMMY.FIL", "w+");
/* write a string into the file */ fwrite(string, strlen(string), 1, stream);
/* seek to the beginning of the file */ fseek(stream, 0, SEEK_SET);
do { /* read a char from the file */ ch = fgetc(stream);
/* display the character */ putch(ch); } while (ch != EOF);
fclose(stream); return 0; }
ㄧ计: fgetchar : 眖瑈い弄才 ノ 猭: int fgetchar(void); 祘ㄒ:
#include <stdio.h>
int main(void) { char ch;
/* prompt the user for input */ printf("Enter a character followed by \ <Enter>: ");
/* read the character from stdin */ ch = fgetchar();
/* display what was read */ printf("The character read is: '%c'\n", ch); return 0; }
ㄧ计: fgetpos : 眔讽玡ゅン琡 ノ 猭: int fgetpos(FILE *stream); 祘ㄒ:
#include <string.h> #include <stdio.h>
int main(void) { FILE *stream; char string[] = "This is a test"; fpos_t filepos;
/* open a file for update */ stream = fopen("DUMMY.FIL", "w+");
/* write a string into the file */ fwrite(string, strlen(string), 1, stream);
/* report the file pointer position */ fgetpos(stream, &filepos); printf("The file pointer is at byte\ %ld\n", filepos);
fclose(stream); return 0; }
ㄧ计: fgets : 眖瑈い弄才﹃ ノ 猭: char *fgets(char *string, int n, FILE *stream); 祘ㄒ:
#include <string.h> #include <stdio.h>
int main(void) { FILE *stream; char string[] = "This is a test"; char msg[20];
/* open a file for update */ stream = fopen("DUMMY.FIL", "w+");
/* write a string into the file */ fwrite(string, strlen(string), 1, stream);
/* seek to the start of the file */ fseek(stream, 0, SEEK_SET);
/* read a string from the file */ fgets(msg, strlen(string)+1, stream);
/* display the string */ printf("%s", msg);
fclose(stream); return 0; }
ㄧ计: filelength : ゅン竊计 ノ 猭: long filelength(int handle); 祘ㄒ:
#include <string.h> #include <stdio.h> #include <fcntl.h> #include <io.h>
int main(void) { int handle; char buf[11] = "0123456789";
/* create a file containing 10 bytes */ handle = open("DUMMY.FIL", O_CREAT); write(handle, buf, strlen(buf));
/* display the size of the file */ printf("file length in bytes: %ld\n", filelength(handle));
/* close the file */ close(handle); return 0; }
ㄧ计: fillellipse : 礶恶掘蛾 ノ 猭: void far fillellipse(int x, int y, int xradius, int yradius); 祘ㄒ:
#include <graphics.h> #include <conio.h>
int main(void) { int gdriver = DETECT, gmode; int xcenter, ycenter, i;
initgraph(&gdriver,&gmode,""); xcenter = getmaxx() / 2; ycenter = getmaxy() / 2;
for (i=0; i<13; i++) { setfillstyle(i,WHITE); fillellipse(xcenter,ycenter,100,50); getch(); }
closegraph(); return 0; } ㄧ计: fillpoly : 礶恶娩 ノ 猭: void far fillpoly(int numpoints, int far *polypoints); 祘ㄒ:
#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h>
int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int i, maxx, maxy;
/* our polygon array */ int poly[8];
/* initialize graphics, local variables */ initgraph(&gdriver, &gmode, "");
/* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ }
maxx = getmaxx(); maxy = getmaxy();
poly[0] = 20; /* 1st vertext */ poly[1] = maxy / 2;
poly[2] = maxx - 20; /* 2nd */ poly[3] = 20;
poly[4] = maxx - 50; /* 3rd */ poly[5] = maxy - 20;
/* 4th vertex. fillpoly automatically closes the polygon. */ poly[6] = maxx / 2; poly[7] = maxy / 2;
/* loop through the fill patterns */ for (i=EMPTY_FILL; i<USER_FILL; i++) { /* set fill pattern */ setfillstyle(i, getmaxcolor());
/* draw a filled polygon */ fillpoly(4, poly);
getch(); }
/* clean up */ closegraph(); return 0; }
ㄧ计: findfirst, findnext : 穓合絃ヘ魁; 眔で皌findfirst家Αゅン ノ 猭: int findfirst(char *pathname, struct ffblk *ffblk, int attrib); int findnext(struct ffblk *ffblk); 祘ㄒ:
/* findnext example */
#include <stdio.h> #include <dir.h>
int main(void) { struct ffblk ffblk; int done; printf("Directory listing of *.*\n"); done = findfirst("*.*",&ffblk,0); while (!done) { printf(" %s\n", ffblk.ff_name); done = findnext(&ffblk); }
return 0; }
ㄧ计: floodfill : 恶Τ跋办 ノ 猭: void far floodfill(int x, int y, int border); 祘ㄒ:
#include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h>
int main(void) { /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int maxx, maxy;
/* initialize graphics, local variables */ initgraph(&gdriver, &gmode, "");
/* read result of initialization */ errorcode = graphresult(); if (errorcode != grOk) /* an error occurred */ { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); exit(1); /* terminate with an error code */ }
maxx = getmaxx(); maxy = getmaxy();
/* select drawing color */ setcolor(getmaxcolor());
/* select fill color */ setfillstyle(SOLID_FILL, getmaxcolor());
/* draw a border around the screen */ rectangle(0, 0, maxx, maxy);
/* draw some circles */ circle(maxx / 3, maxy /2, 50); circle(maxx / 2, 20, 100); circle(maxx-20, maxy-50, 75); circle(20, maxy-20, 25);
/* wait for a key */ getch();
/* fill in bounded region */ floodfill(2, 2, getmaxcolor());
/* clean up */ getch(); closegraph(); return 0; }
ㄧ计: floor : ノ 猭: double floor(double x); 祘ㄒ:
#include <stdio.h> #include <math.h>
int main(void) { double number = 123.54; double down, up;
down = floor(number); up = ceil(number);
printf("original number %10.2lf\n", number); printf("number rounded down %10.2lf\n", down); printf("number rounded up %10.2lf\n", up);
return 0; }
ㄧ计: flushall : 睲埃┮Τ絯≧跋 ノ 猭: int flushall(void); 祘ㄒ:
#include <stdio.h>
int main(void) { FILE *stream;
/* create a file */ stream = fopen("DUMMY.FIL", "w");
/* flush all open streams */ printf("%d streams were flushed.\n", flushall());
/* close the file */ fclose(stream); return 0; }
ㄧ计: fmod : 璸衡x癸y家, x/y计 ノ 猭: double fmod(double x, double y); 祘ㄒ:
#include <stdio.h> #include <math.h>
int main(void) { double x = 5.0, y = 2.0; double result;
result = fmod(x,y); printf("The remainder of (%lf / %lf) is \ %lf\n", x, y, result); return 0; }
ㄧ计: fnmerge : ミ穝ゅン ノ 猭: void fnerge(char *path, char *drive, char *dir); 祘ㄒ:
#include <string.h> #include <stdio.h> #include <dir.h>
int main(void) { char s[MAXPATH]; char drive[MAXDRIVE]; char dir[MAXDIR]; char file[MAXFILE]; char ext[MAXEXT];
getcwd(s,MAXPATH); /* get the current working directory */ strcat(s,"\\"); /* append on a trailing \ character */ fnsplit(s,drive,dir,file,ext); /* split the string to separate elems */ strcpy(file,"DATA"); strcpy(ext,".TXT"); fnmerge(s,drive,dir,file,ext); /* merge everything into one string */ puts(s); /* display resulting string */
return 0; }
ㄧ计: fopen : ゴ秨瑈 ノ 猭: FILE *fopen(char *filename, char *type); 祘ㄒ:
#include <stdlib.h> #include <stdio.h> #include <dir.h>
int main(void) { char *s; char drive[MAXDRIVE]; char dir[MAXDIR]; char file[MAXFILE]; char ext[MAXEXT]; int flags;
s=getenv("COMSPEC"); /* get the comspec environment parameter */ flags=fnsplit(s,drive,dir,file,ext);
printf("Command processor info:\n"); if(flags & DRIVE) printf("\tdrive: %s\n",drive); if(flags & DIRECTORY) printf("\tdirectory: %s\n",dir); if(flags & FILENAME) printf("\tfile: %s\n",file); if(flags & EXTENSION) printf("\textension: %s\n",ext);
return 0; }
ㄧ计: fprintf : 肚癳Αて块瑈い ノ 猭: int fprintf(FILE *stream, char *format[, argument,...]); 祘ㄒ:
/* Program to create backup of the AUTOEXEC.BAT file */
#include <stdio.h>
int main(void) { FILE *in, *out;
if ((in = fopen("\\AUTOEXEC.BAT", "rt")) == NULL) { fprintf(stderr, "Cannot open input \ file.\n"); return 1; }
if ((out = fopen("\\AUTOEXEC.BAK", "wt")) == NULL) { fprintf(stderr, "Cannot open output \ file.\n"); return 1; }
while (!feof(in)) fputc(fgetc(in), out);
fclose(in); fclose(out); return 0; }
ㄧ计: FP_OFF : 莉环熬簿秖 ノ 猭: unsigned FP_OFF(void far *farptr); 祘ㄒ:
/* FP_OFF */
#include <dos.h> #include <stdio.h>
int main(void) { char *str = "fpoff.c";
printf("The offset of this file in memory\ is: %Fp\n", FP_OFF(str));
return 0; }
ㄧ计: FP_SEG : 莉环琿 ノ 猭: unsigned FP_SEG(void far *farptr); 祘ㄒ:
/* FP_SEG */
#include <dos.h> #include <stdio.h>
int main(void) { char *filename = "fpseg.c";
printf("The offset of this file in memory\ is: %Fp\n", FP_SEG(filename));
return(0); }
ㄧ计: fputc : 癳才瑈い ノ 猭: int fputc(int ch, FILE *stream); 祘ㄒ:
#include <stdio.h>
int main(void) { char msg[] = "Hello world"; int i = 0;
while (msg[i]) { fputc(msg[i], stdout); i++; } return 0; }
ㄧ计: fputchar : 癳才夹非块瑈(stdout)い ノ 猭: int fputchar(char ch); 祘ㄒ:
#include <stdio.h>
int main(void) { char msg[] = "This is a test"; int i = 0;
while (msg[i]) { fputchar(msg[i]); i++; } return 0; }
ㄧ计: fputs : 癳才瑈い ノ 猭: int fputs(char *string, FILE *stream); 祘ㄒ:
#include <stdio.h>
int main(void) { /* write a string to standard output */ fputs("Hello world\n", stdout);
return 0; }
ㄧ计: fread : 眖瑈い弄计沮 ノ 猭: int fread(void *ptr, int size, int nitems, FILE *stream); 祘ㄒ:
#include <string.h> #include <stdio.h>
int main(void) { FILE *stream; char msg[] = "this is a test"; char buf[20];
if ((stream = fopen("DUMMY.FIL", "w+")) == NULL) { fprintf(stderr, "Cannot open output file.\n"); return 1; }
/* write some data to the file */ fwrite(msg, strlen(msg)+1, 1, stream);
/* seek to the beginning of the file */ fseek(stream, SEEK_SET, 0);
/* read the data and display it */ fread(buf, strlen(msg)+1, 1, stream); printf("%s\n", buf);
fclose(stream); return 0; }
ㄧ计: free : 睦だ皌遏 ノ 猭: void free(void *ptr); 祘ㄒ:
#include <string.h> #include <stdio.h> #include <alloc.h>
int main(void) { char *str;
/* allocate memory for string */ str = malloc(10);
/* copy "Hello" to string */ strcpy(str, "Hello");
/* display string */ printf("String is %s\n", str);
/* free memory */ free(str);
return 0; }
ㄧ计: freemem : 睦玡だ皌DOSず遏 ノ 猭: int freemem(unsigned seg); 祘ㄒ:
#include <dos.h> #include <alloc.h> #include <stdio.h>
int main(void) { unsigned int size, segp; int stat;
size = 64; /* (64 x 16) = 1024 bytes */ stat = allocmem(size, &segp); if (stat < 0) printf("Allocated memory at segment:\ %x\n", segp); else printf("Failed: maximum number of\ paragraphs available is %u\n", stat); freemem(segp);
return 0; }
ㄧ计: freopen : 蠢传瑈 ノ 猭: FILE *freopen(char *filename, char *type, FILE *stream); 祘ㄒ:
#include <stdio.h>
int main(void) { /* redirect standard output to a file */ if (freopen("OUTPUT.FIL", "w", stdout) == NULL) fprintf(stderr, "error redirecting\ stdout\n");
/* this output will go to a file */ printf("This will go into a file.");
/* close the standard output stream */ fclose(stdout);
return 0; }
ㄧ计: frexp : р蛮弘计だ秆Ю计计 ノ 猭: double frexp(double value, int *eptr); 祘ㄒ:
#include <math.h> #include <stdio.h>
int main(void) { double mantissa, number; int exponent;
number = 8.0; mantissa = frexp(number, &exponent);
printf("The number %lf is ", number); printf("%lf times two to the ", mantissa); printf("power of %d\n", exponent);
return 0; }
ㄧ计: fscanf : 眖瑈い磅︽Αて块 ノ 猭: int fscanf(FILE *stream, char *format[,argument...]); 祘ㄒ:
#include <stdlib.h> #include <stdio.h>
int main(void) { int i;
printf("Input an integer: ");
/* read an integer from the standard input stream */ if (fscanf(stdin, "%d", &i)) printf("The integer read was: %i\n", i); else { fprintf(stderr, "Error reading an \ integer from stdin.\n"); exit(1); } return 0; }
ㄧ计: fseek : ﹚瑈ゅン皐 ノ 猭: int fseek(FILE *stream, long offset, int fromwhere); 祘ㄒ:
#include <stdio.h>
long filesize(FILE *stream);
int main(void) { FILE *stream;
stream = fopen("MYFILE.TXT", "w+"); fprintf(stream, "This is a test"); printf("Filesize of MYFILE.TXT is %ld bytes\n", filesize(stream)); fclose(stream); return 0; }
long filesize(FILE *stream) { long curpos, length;
curpos = ftell(stream); fseek(stream, 0L, SEEK_END); length = ftell(stream); fseek(stream, curpos, SEEK_SET); return length; }
ㄧ计: fsetpos : ﹚瑈ゅン皐 ノ 猭: int fsetpos(FILE *stream, const fpos_t *pos); 祘ㄒ:
#include <stdlib.h> #include <stdio.h>
void showpos(FILE *stream);
int main(void) { FILE *stream; fpos_t filepos;
/* open a file for update */ stream = fopen("DUMMY.FIL", "w+");
/* save the file pointer position */ fgetpos(stream, &filepos);
/* write some data to the file */ fprintf(stream, "This is a test");
/* show the current file position */ showpos(stream);
/* set a new file position, display it */ if (fsetpos(stream, &filepos) == 0) showpos(stream); else { fprintf(stderr, "Error setting file \ pointer.\n"); exit(1); }
/* close the file */ fclose(stream); return 0; }
void showpos(FILE *stream) { fpos_t pos;
/* display the current file pointer position of a stream */ fgetpos(stream, &pos); printf("File position: %ld\n", pos); }
ㄧ计: fstat : 莉ゴ秨ゅン獺 ノ 猭: int fstat(char *handle, struct stat *buff); 祘ㄒ:
#include <sys\stat.h> #include <stdio.h> #include <time.h>
int main(void) { struct stat statbuf; FILE *stream;
/* open a file for update */ if ((stream = fopen("DUMMY.FIL", "w+")) == NULL) { fprintf(stderr, "Cannot open output \ file.\n"); return(1); } fprintf(stream, "This is a test"); fflush(stream);
/* get information about the file */ fstat(fileno(stream), &statbuf); fclose(stream);
/* display the information returned */ if (statbuf.st_mode & S_IFCHR) printf("Handle refers to a device.\n"); if (statbuf.st_mode & S_IFREG) printf("Handle refers to an ordinary \ file.\n"); if (statbuf.st_mode & S_IREAD) printf("User has read permission on \ file.\n"); if (statbuf.st_mode & S_IWRITE) printf("User has write permission on \ file.\n");
printf("Drive letter of file: %c\n", 'A'+statbuf.st_dev); printf("Size of file in bytes: %ld\n", statbuf.st_size); printf("Time file last opened: %s\n", ctime(&statbuf.st_ctime)); return 0; }
ㄧ计: ftell : 讽玡ゅン皐 ノ 猭: long ftell(FILE *stream); 祘ㄒ:
#include <stdio.h>
int main(void) { FILE *stream;
stream = fopen("MYFILE.TXT", "w+"); fprintf(stream, "This is a test"); printf("The file pointer is at byte \ %ld\n", ftell(stream)); fclose(stream); return 0; }
ㄧ计: fwrite : 糶ず甧瑈い ノ 猭: int fwrite(void *ptr, int size, int nitems, FILE *stream); 祘ㄒ:
#include <stdio.h>
struct mystruct { int i; char ch; };
int main(void) { FILE *stream; struct mystruct s;
if ((stream = fopen("TEST.$$$", "wb")) == NULL) /* open file TEST.$$$ */ { fprintf(stderr, "Cannot open output file.\n"); return 1; } s.i = 0; s.ch = 'A'; fwrite(&s, sizeof(s), 1, stream); /* write struct s to file */ fclose(stream); /* close file */ return 0; }
(http://www.fanqiang.com)
秈UNIX阶韭
|