MentOS  0.8.0
The Mentoring Operating System
Macros | Functions
stdio.h File Reference

Standard I/0 functions. More...

Go to the source code of this file.

Macros

#define MAX_DIGITS_IN_INTEGER   11
 The maximum number of digits of an integer.
 
#define GETS_BUFFERSIZE   255
 The size of 'gets' buffer.
 
#define SEEK_SET   0
 The file offset is set to offset bytes.
 
#define SEEK_CUR   1
 The file offset is set to its current location plus offset bytes.
 
#define SEEK_END   2
 The file offset is set to the size of the file plus offset bytes.
 

Functions

void putchar (int character)
 Writes the given character to the standard output (stdout). More...
 
void puts (const char *str)
 Writes the string pointed by str to the standard output (stdout) and appends a newline character. More...
 
int getchar (void)
 Returns the next character from the standard input (stdin). More...
 
char * gets (char *str)
 Reads characters from the standard input (stdin). More...
 
int fgetc (int fd)
 Same as getchar but reads from the given file descriptor. More...
 
char * fgets (char *buf, int n, int fd)
 Same as gets but reads from the given file descriptor. More...
 
int atoi (const char *str)
 Convert the given string to an integer. More...
 
long strtol (const char *str, char **endptr, int base)
 Converts the initial part of str to a long int value according to the given base, which. More...
 
int printf (const char *fmt,...)
 Write formatted output to stdout. More...
 
int sprintf (char *str, const char *fmt,...)
 Write formatted output to str. More...
 
int fprintf (int fd, const char *fmt,...)
 Write formatted output to a file. More...
 
int vfprintf (int fd, const char *fmt, va_list args)
 Write formatted data from variable argument list to a file. More...
 
int vsprintf (char *str, const char *fmt, va_list args)
 Write formatted data from variable argument list to string. More...
 
int scanf (const char *fmt,...)
 Read formatted input from stdin. More...
 
int sscanf (const char *str, const char *fmt,...)
 Read formatted data from string. More...
 
int fscanf (int fd, const char *fmt,...)
 The same as sscanf but the source is a file. More...
 
void perror (const char *s)
 Prints a system error message. More...
 

Detailed Description

Standard I/0 functions.

Function Documentation

◆ atoi()

int atoi ( const char *  str)

Convert the given string to an integer.

Parameters
strThe string to convert.
Returns
The integer contained inside the string.

◆ fgetc()

int fgetc ( int  fd)

Same as getchar but reads from the given file descriptor.

Parameters
fdThe file descriptor from which it reads.
Returns
The read character.

◆ fgets()

char* fgets ( char *  buf,
int  n,
int  fd 
)

Same as gets but reads from the given file descriptor.

Parameters
bufThe buffer where the string should be placed.
nThe amount of characters to read.
fdThe file descriptor from which it reads.
Returns
The read string.

◆ fprintf()

int fprintf ( int  fd,
const char *  fmt,
  ... 
)

Write formatted output to a file.

Parameters
fdThe file descriptor associated with the file.
fmtFormat string, following the same specifications as printf.
...The list of arguments.
Returns
On success, the total number of characters written is returned. On failure, a negative number is returned.

◆ fscanf()

int fscanf ( int  fd,
const char *  fmt,
  ... 
)

The same as sscanf but the source is a file.

Parameters
fdThe file descriptor associated with the file.
fmtFormat string, following the same specifications as printf.
...The list of arguments where the values are stored.
Returns
On success, the function returns the number of items of the argument list successfully filled. EOF otherwise.

◆ getchar()

int getchar ( void  )

Returns the next character from the standard input (stdin).

Returns
The character received from stdin.

◆ gets()

char* gets ( char *  str)

Reads characters from the standard input (stdin).

Parameters
strWhere the characters are stored.
Returns
The string received from standard input.

◆ perror()

void perror ( const char *  s)

Prints a system error message.

Parameters
sthe message we prepend to the actual error message.

◆ printf()

int printf ( const char *  fmt,
  ... 
)

Write formatted output to stdout.

Parameters
fmtThe format string.
...The list of arguments.
Returns
On success, the total number of characters written is returned. On failure, a negative number is returned.

◆ putchar()

void putchar ( int  character)

Writes the given character to the standard output (stdout).

Parameters
characterThe character to send to stdout.

◆ puts()

void puts ( const char *  str)

Writes the string pointed by str to the standard output (stdout) and appends a newline character.

Parameters
strThe string to send to stdout.

◆ scanf()

int scanf ( const char *  fmt,
  ... 
)

Read formatted input from stdin.

Parameters
fmtFormat string, following the same specifications as printf.
...The list of arguments where the values are stored.
Returns
On success, the function returns the number of items of the argument list successfully filled. EOF otherwise.

◆ sprintf()

int sprintf ( char *  str,
const char *  fmt,
  ... 
)

Write formatted output to str.

Parameters
strThe buffer where the formatted string will be placed.
fmtFormat string, following the same specifications as printf.
...The list of arguments.
Returns
On success, the total number of characters written is returned. On failure, a negative number is returned.

◆ sscanf()

int sscanf ( const char *  str,
const char *  fmt,
  ... 
)

Read formatted data from string.

Parameters
strString processed as source to retrieve the data.
fmtFormat string, following the same specifications as printf.
...The list of arguments where the values are stored.
Returns
On success, the function returns the number of items of the argument list successfully filled. EOF otherwise.

◆ strtol()

long strtol ( const char *  str,
char **  endptr,
int  base 
)

Converts the initial part of str to a long int value according to the given base, which.

Parameters
strThis is the string containing the integral number.
endptrSet to the character after the numerical value.
baseThe base must be between 2 and 36 inclusive, or special 0.
Returns
Integral number as a long int value, else zero value is returned.

◆ vfprintf()

int vfprintf ( int  fd,
const char *  fmt,
va_list  args 
)

Write formatted data from variable argument list to a file.

Parameters
fdThe file descriptor associated with the file.
fmtFormat string, following the same specifications as printf.
argsA variable arguments list.
Returns
On success, the total number of characters written is returned. On failure, a negative number is returned.

◆ vsprintf()

int vsprintf ( char *  str,
const char *  fmt,
va_list  args 
)

Write formatted data from variable argument list to string.

Parameters
strPointer to a buffer where the resulting C-string is stored.
fmtFormat string, following the same specifications as printf.
argsA variable arguments list.
Returns
On success, the total number of characters written is returned. On failure, a negative number is returned.