10.01.2007, 09:26
общий
это ответ
Здравствуйте, Holyman!
Прототип функции чтения строки из текстово-типизированного файла:
char *fgets(char *s, int n, FILE *stream);
Remarks:
fgets reads characters from stream into the string s. It stops when it reads
either n - 1 characters or a newline character, whichever comes first.
fgets retains the newline character at the end of s and appends a null byte
to s to mark the end of the string.
Return Value:
■ On success,
■ fgets returns the string pointed to by s.
■ fputs returns the last character written.
■ On end-of-file or error, fgets returns null.
■ On error, fputs returns EOF.
Portability:
╔ DOS ╤ UNIX ╤ Windows ╤ ANSI C ╤ C++ Only ╗
║ Yes │ Yes │ Yes │ Yes │ ║
╚═════╧══════╧═════════╧════════╧══════════╝
See Also:
cgets gets puts fputs
Пример использования - в приложении.
Если с буржуйским - проблемы, могу перевести на великий и могучий.
Приложение:
#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;}