UP | HOME

C语言库函数备忘

Table of Contents

文件操作:

FILE*   fopen(const char* name, const char* mode);
int     fclose(FILE* fp);
FILE*   fdopen(int filedes, const char* mode);

long    ftell(FILE *fp);
int fseek(FILE* fp, long offset, int whence);
void    rewind(FILE* fp)

流操作:

字符操作:

int     getc(FILE* fp);
int fgetc(FILE* fp);
int getchar(); 
int ungetc(int c, FILE* FP)

int putc(int c, FILE *fp);
int fputc(int c, FILE* fp);
int putchar(int c);
        Return EOF on end or error. 

行操作

char*   fgets(char* buf, int n, FILE* fp);
char*   gets(char* buf); //Never use. 
        Return NULL on end or error

int fputs(const char* str, FILE* fp);
int puts(const char* str);

二进制流操作

size_t  fread(void* ptr, size_t size, size_t nobj, FILE* fp);
size_t  fwrite(const void* ptr, size_t size, size_t nobj, FILE* fp);

字符串操作:

strcat(s, t)        将t接到s后
strncat(s, t, n)    

strcmp(s, t)    s<t 小于0 ; s==t 等于0; s>t 大于0
strncmp(s, t)

strcpy(s, t)      将t复制到s
strncpy(s, t, n)

strlen(s)
strchr(s, int c)    在s中查找c,找到则返回第一次出现到指针,否则返回NULL
strrchr(s, int c)   在s中查找c,找到则返回最后一次出现到指针,否则返回NULL
strstr(s, c)

Author: Le Cao

Date: 2010-10-12 23:36:10 CST

HTML generated by org-mode TAG=7.01g in emacs 23