|
Cet article a fait l'objet d'une traduction automatique. Déplacez votre pointeur sur les phrases de l'article pour voir la version originale de ce texte. Informations supplémentaires.
|
Traduction
Source
|
getc, getwc
int getc( FILE *stream ); wint_t getwc( FILE *stream );
|
|
|
|---|---|
|
getc |
|
|
getwc |
|
|
|
|
|
|
|---|---|---|---|
|
_gettc |
getc |
getc |
getwc |
|
|
|
|---|---|
|
getc |
|
|
getwc |
|
// crt_getc.c
// Use getc to read a line from a file.
#include <stdio.h>
int main()
{
char buffer[81];
int i, ch;
FILE* fp;
// Read a single line from the file "crt_getc.txt".
fopen_s(&fp, "crt_getc.txt", "r");
if (!fp)
{
printf("Failed to open file crt_getc.txt.\n");
exit(1);
}
for (i = 0; (i < 80) && ((ch = getc(fp)) != EOF)
&& (ch != '\n'); i++)
{
buffer[i] = (char) ch;
}
// Terminate string with a null character
buffer[i] = '\0';
printf( "Input was: %s\n", buffer);
fclose(fp);
}
Sortie