Input/Output Flashcards
standard input stream
stdin
standard output stream
stdout
standard error stream
stderr
end of file (type is int)
EOF
get a character
getchar()
print a character
putchar(chr )
print formatted data
printf(“format “,arg 1 ,. . . )
print to string s
sprintf(s,”format “,arg 1 ,. . . )
read formatted data
scanf(“format “,&name 1 ,. . . )
read from string s
sscanf(s,”format “,&name 1 ,. . . )
print string s
puts(s)
declare file pointer
FILE *fp;
pointer to named file
fopen(“name”,”mode”)
modes: r (read), w (write), a (append), b (binary)
get a character
getc(fp)
write a character
putc(chr,fp)
write to file
fprintf(fp,”format”,arg1,. . . )
read from file
fscanf(fp,”format”,arg1,. . . )
read and store n elts to *ptr
fread(*ptr,eltsize,n,fp)
write n elts from *ptr to file
fwrite(*ptr,eltsize,n,fp)
close file
fclose(fp )
non-zero if error
ferror(fp )
non-zero if already reached EOF
feof(fp)
read line to string s (< max chars)
fgets(s, max, fp)
write string s
fputs(s,fp)
h
short
l
long
L
long double