fopen

 

ファイルをオープン (open) します.

#include <stdio.h>
FILE *fopen(
    const char * restrict filename,
    const char * restrict mode
);

fopen 関数はfilename が指す文字列を名前とするファイルを mode が指すモードでオープンし,そのファイルにストリーム (stream) を結び付けます.

引数 mode は文字列で指定します.定義されていないモードを指定した場合の動作は未定義です.

引数

  • filename: ファイル名
  • mode: モード (下記を参照してください)

戻り値

 

プログラムの書き方

 

int main(void)
{

FILE *rfp;
char buf[2048];
char *look;
char find[1024] = "root";

if *1 == NULL ) {

fprintf(stderr,"ERROR");
}

while( fgets(buf,BUF,rfp) != NULL ) {

if*2 != NULL ) {

printf("%s",look);
}
}
}

 

*1:rfp = fopen("/etc/passwd","r"

*2: look = strstr(buf,find