Escolar Documentos
Profissional Documentos
Cultura Documentos
#include <stdio.h>
fopen
FILE *fopen( const char *fname, const char *mode );
The fopen() function opens a file indicated by fname and returns a
פלט
stream associated with that file. If there is an error, fopen() returns
מצביע לקובץ :הצלחה
NULL. mode is used to determine how the file will be treated (i.e.
NULL :כשלון
for input, output, etc)
Modes:
r Open a text file for reading
w Create a text file for writing
a Append to a text file
r+ Open a text file for read/write
w+ Create a text file for read/write
a+ Open a text file for read/write
fclose
int fclose( FILE *stream );
The function fclose() closes the given file stream, deallocating any פלט
buffers associated with that stream. fclose() returns 0 upon 0 :הצלחה
success, and EOF otherwise. EOF :כשלון
פלט/קבצים – קלט
#include <stdio.h>
char
fgetc
int fgetc( FILE *stream );
פלט
The fgetc() function returns the next character from stream, or EOF
התו הבא :הצלחה
if the end of file is reached or if there is an error.
EOF :כשלון
fputc
int fputc( int ch, FILE *stream );
The function fputc() writes the given character ch to the given פלט
output stream. The return value is the character, unless there is an התו שהודפס :הצלחה
error, in which case the return value is EOF. EOF :כשלון
string
fgets
char *fgets( char *str, int num, FILE *stream );
The function fgets() reads up to num - 1 characters from the given
file stream and dumps them into str. fgets() will stop when it
פלט
reaches the end of a line, in which case str will be terminated with a
מחרוזת :הצלחה
newline. If fgets() reaches num - 1 characters or encounters the
NULL :כשלון
EOF, str will be null-terminated. fgets() returns str on success, and
NULL on an error
fputs
int fputs( const char *str, FILE *stream );
The fputs() function writes an array of characters pointed to by str to פלט
the given output stream. The return value is non-negative on 0 ≥ מספר :הצלחה
success, and EOF on failure. EOF :כשלון
different formats
fscanf
int fscanf( FILE *stream, const char *format, ... );
The function fscanf() reads data from the given file stream in a פלט
manner exactly like scanf(). The return value of fscanf() is the מס' המשתנים :הצלחה
number of variables that are actually assigned values, or EOF if no .שנקלטו
assignments could be made. EOF :כשלון
fprintf
int fprintf( FILE *stream, const char *format, ... );
The fprintf() function sends information (the arguments) according
פלט
to the specified format to the file indicated by stream. fprintf() works
מספר התווים :הצלחה
just like printf() as far as the format goes. The return value of
.שהודפסו
fprintf() is the number of characters outputted, or a negative number
.מספר שלילי :כשלון
if an error occurs.
פלט/קלט
#include <stdio.h>
char
getc
int getc( FILE *stream );
פלט
The getc() function returns the next character from stream, or EOF
התו הבא :הצלחה
if the end of file is reached. getc() is identical to fgetc().
EOF :כשלון
getchar
int getchar( void );
פלט
The getchar() function returns the next character from STDIN, or
התו הבא :הצלחה
EOF if the end of file is reached.
EOF :כשלון
putc
int putc( int ch, FILE *stream );
פלט
The putc() function writes the character ch to stream. The return
התו שהודפס :הצלחה
value is the character written, or EOF if there is an error.
EOF :כשלון
putchar
int putchar( int ch );
פלט
The putchar() function writes ch to STDOUT.The value returned is
התו שהודפס :הצלחה
the written character. If an error occurs, EOF is returned.
EOF :כשלון
string
gets
char *gets( char *str );
The gets() function reads characters from STDIN and loads them
פלט
into str, until a newline or EOF is reached. The newline character is
מחרוזת :הצלחה
translated into a null termination. The return value of gets() is the
NULL :כשלון
read-in string, or NULL if there is an error.
puts
int puts( char *str );
פלט
The function puts() writes str to STDOUT. puts() returns non-
0 ≥ מספר :הצלחה
negative on success, or EOF on failure.
EOF :כשלון
different formats
printf
int printf( const char *format, ... );
The printf() function prints output to STDOUT, according to format
and other arguments passed to printf(). The string format consists
of two types of items - characters that will be printed to the screen, פלט
and format commands that define how the other arguments to מחרוזת :הצלחה
printf() are displayed. Basically, you specify a format string that has NULL :כשלון
text in it, as well as "special" characters that map to the other
arguments of printf().
scanf
int scanf( const char *format, ... );
The scanf() function reads input from STDIN, according to the given
format, and stores the data in the other arguments. It works a lot
פלט
like printf(). The format string consists of control characters,
מס' המשתנים :הצלחה
whitespace characters, and non-whitespace characters. The return
.שנקלטו
value us the number of items succesfully read. This count doesn't
EOF :כשלון
include any ignored fields with asterisks (*) or EOF if an error has
occurred before the first assignation could be done.
Code Format
%d signed integers
%i signed integers
%u unsigned integer
%f floating point
%c character
%s a string of characters
%e scientific notation, with a lowercase "e"
%E scientific notation, with a uppercase "E"
%g use %e or %f, whichever is shorter
%G use %E or %f, whichever is shorter
%p a pointer
סיכום פונקציות
כתיבה קריאה
קובץ default קובץ default
fputc putc fgetc getc
fputchar putchar fgetchar getchar
תו
atof
double atof( const char *str );
The function atof() converts str into a double, then returns that פלט
value. str must start with a valid number, but can be terminated with double :הצלחה
any non-numerical character, other than "E" or "e". 0 :כשלון
x = atof( "42.0is_the_answer" ); // x = 42.0
atoi
int atoi( const char *str );
The atoi() function converts str into an integer, and returns that
פלט
integer. str should start with some sort of number, and atoi() will
integer :הצלחה
stop reading from str as soon as a non-numerical character has
0 :כשלון
been read.
i = atoi( "512.035" ); // i = 512
atol
long atol( const char *str );
The function atol() converts str into a long, then returns that value.
פלט
atol() will read from str until it finds any character that should not be
long :הצלחה
in a long. The resulting truncated value is then converted and
0 :כשלון
returned.
#include <stdlib.h>
strcat
char *strcat( char *str1, const char *str2 );
פלט
The strcat() function concatenates str2 onto the end of str1, and
str1=str1+str2 :הצלחה
returns str1.
0 :כשלון
strchr
char *strchr( const char *str, int ch );
פלט
The function strchr() returns a pointer to the first occurence of ch in פוינטר למופע :הצלחה
str, or NULL if ch is not found. .הראשון
NULL :כשלון
strcmp
int strcmp( const char *str1, const char *str2 );
The function strcmp() compares str1 and str2, then returns:
פלט
less than 0 ''str1'' is less than ''str2''
מספר :הצלחה
equal to 0 ''str1'' is equal to ''str2''
? :כשלון
greater than 0 ''str1'' is greater than ''str2''
strcpy
char *strcpy( char *to, const char *from );
פלט
The strcpy() function copies characters in the string from to the
מחרוזת היעד :הצלחה
string to, including the null termination. The return value is to.
? :כשלון
strlen
size_t strlen( char *str );
פלט
The strlen() function returns the length of str (determined by the
אורך המחרוזת :הצלחה
number of characters before null termination).
? :כשלון
#include <ctypeh>
tolower
int tolower( int ch );
פלט
The function tolower() returns the lowercase version of the
אות קטנה :הצלחה
character ch.
? :כשלון
toupper
int toupper( int ch );
פלט
The toupper() function returns the uppercase version of the
אות גדולה :הצלחה
character ch.
? :כשלון
isupper
int isupper( int ch );
פלט
The isupper() function returns non-zero if its argument is an אות קטנה-0 :הצלחה
uppercase letter. Otherwise, zero is returned. מס' – גדולה
? :כשלון