MOHAMED
MOHAMED

Reputation: 43616

Equivalent function of fgets for open

With fopen() I read the file line by line with fgets().

Are there a function like fgets() inorder to read stream opened by open() ?

Upvotes: 0

Views: 1736

Answers (2)

John
John

Reputation: 1

Are you trying to read the standard input? If so....

char line[1000]; FILE *fpin;

fpin=stdin; while(fgets(line,1000,fpin)!=NULL) printf("%s",line);

Upvotes: -1

Anton Kovalenko
Anton Kovalenko

Reputation: 21517

There is no such function. The problem is, unless you do buffering in userspace (like FILE* routines do), there is no way to implement it efficiently: you'll have to read characters one-by-one.

On POSIX systems you can use fdopen to wrap a FILE* structure around a file descriptor, and then use fgets.

Upvotes: 2

Related Questions