Você está na página 1de 29

CSC1402 Foundation Computing

Appendix A1
Simplified C Standard Library
Reference

A1.1

CSC1402 Foundation Computing

A1.2

Introduction
This is a limited set of functions and constants from the C Standard Libraries. The
functions and constants given are relevant to an introductory programming course in
C/C++ using a procedural paradigm first approach.

Table of Contents
A1.1.

Character Handling <ctype.h> ......................................................................... 3

A1.2.

Mathematics <math.h> .................................................................................... 5

A1.3.

Input/Output <stdio.h> .................................................................................... 7

A1.4.

String Conversion, Random Numbers and Other <stdlib.h>......................... 15

A1.5.

String Handling <string.h> ............................................................................ 17

A1.6.

Date and Time <time.h> ................................................................................ 20

A1.7.

Reserved Words ............................................................................................. 24

A1.8.

ASCII Table ................................................................................................... 25

Standard Library Index ................................................................................................ 26

CSC1402 Foundation Computing

A1.3

A1.1. Character Handling <ctype.h>


int isalnum (int charToTest);
Returns 1 (equivalent to true) if charToTest is an alphabetic character or
numeric digit character. Returns 0 (equivalent to false) otherwise.
The following statements output 1.
printf("%i\n", isalnum('1'));
printf("%i\n", isalnum('a'));
The following outputs 0.
printf("%i\n", isalnum('#'));
int isalpha (int charToTest);
Returns 1 (equivalent to true) if charToTest is an alphabetic character. Returns 0
(equivalent to false) otherwise.
The following outputs 1.
printf("%i\n", isalnum('a'));
The following outputs 0.
printf("%i\n", isalnum('#'));
int isdigit (int charToTest);
Returns 1 (equivalent to true) if charToTest is a numeric digit character. Returns
0 (equivalent to false) otherwise.
The following outputs 1.
printf("%i\n", isalnum('a'));
The following outputs 0.
printf("%i\n", isalnum('#'));
int islower (int charToTest);
Returns 1 (equivalent to true) if charToTest is a lower case alphabetic character.
Returns 0 (equivalent to false) otherwise.

CSC1402 Foundation Computing

A1.4

The following outputs 1.


printf("%i\n", isalnum('a'));
The following outputs 0.
printf("%i\n", isalnum('A'));
int isspace (int charToTest);
Returns 1 (equivalent to true) if charToTest is a whitespace character. Returns 0
(equivalent to false) otherwise.
The following outputs 1.
printf("%i\n", isalnum(' '));
The following outputs 0.
printf("%i\n", isalnum('#'));
int isupper (int charToTest);
Returns 1 (equivalent to true) if charToTest is an upper case alphabetic
character. Returns 0 (equivalent to false) otherwise.
The following outputs 1.
printf("%i\n", isalnum('A'));
The following outputs 0.
printf("%i\n", isalnum('a'));
int tolower (int charToConvert);
Returns a lower case equivalent of charToConvert if it is an upper case alphabetic
character. Returns the value of charToTest otherwise.
The following outputs the letter a.
printf("%c\n", tolower('A'));
int toupper (int charToConvert);
Returns an upper case equivalent of charToConvert if it is a lower case alphabetic
character. Returns the value of charToTest otherwise.
The following outputs the letter A.
printf("%c\n", tolower('a'));

CSC1402 Foundation Computing

A1.5

A1.2. Mathematics <math.h>


double ceil (double numberToBeRounded);
Returns the next whole number after numberToBeRounded in a positive direction
on the number line. For example when numberToBeRounded is 1.23 ceil returns
2.0; when numberToBeRounded is -1.23 ceil returns -1.0.
The following outputs 2.000000.
printf("%lf\n", ceil(1.23));
The following outputs -1.000000.
printf("%lf\n", ceil(-1.23));
double cos (double angleInRadians);
Returns the cosine of angleInRadians which is an angle measurement in radians.
double exp (double x);
Returns the exponential function of x (ex).
double fabs (double number);
Returns the absolute value of number. Where number is negative, its positive value
is returned.
double floor (double numberToBeRounded);
Returns the next whole number after numberToBeRounded in a positive direction
on the number line. For example when numberToBeRounded is 1.23 ceil returns
2.0; when numberToBeRounded is -1.23 ceil returns -1.0.
The following outputs 6.000000.
printf("%lf\n", floor(6.78));
The following outputs -7.000000.
printf("%lf\n", ceil(-6.78));
double log (double x);
Returns the natural logarithm of x (logex).
double log10 (double x);
Returns the base-ten logarithm of x (log10x).

CSC1402 Foundation Computing

A1.6

double pow (double base, double exponent);


Returns base to the power exponent (baseexponent) for example x2 can be achieved
by pow(x,2);
The following outputs 9.000000.
printf("%lf\n", pow(2.0, 3.0));
double sin (double angleInRadians);
Returns the sine of angleInRadians which is an angle measurement in radians.
double sqrt (double x);
Returns the square root of x. (x)
The following outputs 3.000000.
printf("%lf\n", sqrt(9.0));
double tan (double angleInRadians);
Returns the tangent of angleInRadians which is an angle measurement in
radians.

CSC1402 Foundation Computing

A1.7

A1.3. Input/Output <stdio.h>


EOF

Macro value returned by some functions to indicate end of file.

int fclose (FILE *stream);


Closes the file opened on stream and returns 0 for success or EOF on failure.
The following call closes the file attached to stream.
fclose(stream);
int feof (FILE *stream);
Returns 1 (equivalent to true) if the EOF indicator is set for stream (ie. stream
has reached the end of file).
The following loop will repeat until stream reaches the end of the file it is attached
to.
while(!feof(stream)) { ...
int fgetc (FILE *stream);
Returns the next character from stream, as an unsigned char converted to an
int (as an ASCII code). Returns EOF if an error occurs, for instance, the end of file
has been reached.
The following call closes inputs a character from stream.
char inputCharacter;
inputCharacter = fgetc(stream);
char *fgets (char *string, int maxChars, FILE *stream);
Reads a string from stream to memory at *string up to maxChars-1 characters
or until the end of line is reached before reading maxChars-1 characters. If reading
stops at the end of a line, the newline character will be read in and may have to be
removed. Adds a null (\0) character at the end of the string. Returns string (the
location of the start of the string read in) on success or NULL on failure.
The following call inputs a string from stream.
char inputString[256];
fgets(inputString, 256, stream);

CSC1402 Foundation Computing

A1.8

FILE *fopen (const char *filename, const char *mode);


Opens the file named filename; returns the address of a stream on success or NULL
on failure. The argument mode should be one of the following strings. Add b to the
mode to open a binary file.
r

reading

opens existing file at start

writing

creates a file if non-existent or truncates existing file

appending

creates a file if non-existent or starts at end of existing file

r+ reading and writing

opens existing file at start for updating

w+ reading and writing

creates a file if non-existent or truncates existing file

a+ reading and writing

creates a file if non-existent or starts at end of existing file

The following call opens the file output.txt for writing.


FILE *outputStream;
outputStream = fopen("output.txt", "w");
int fprintf (FILE *stream, const char *format, ...);
Writes to stream according to format substituting format sequences with further
arguments. Returns the number of successfully characters output or a negative value if
an error occurs.
The following call outputs the value 5 to outputStream.
fprintf(outputStream, "%i", 5);
Format Sequence
The following format sequences are used with expressions of specific types.
%c

char

%i or %d

int

%s

string

%u

unsigned int

%li or %D

long int

%lu or %U

long unsigned int

%hi

short int

%hu

short unsigned int

%f

float

%lf

double

%L

long double

%%

percentage symbol

CSC1402 Foundation Computing

A1.9

Field Width
Field width can be used to control the output format of expressions where a columnar
output is needed.
For Integers, Strings, and Single Characters

Placing a number between the % and format specifier for a format sequence will cause
the integer to be output right-justified in a field width with that number of spaces. For
example %3i will output numbers in a field width of 3 spaces. If the integer being
output is longer than the field width, the field width will be 'pushed out' to
accommodate the integer.
The following call outputs the value 5 in a field width of 3.
fprintf(outputStream, "%3i", 5);
For Floating Point Numbers

A field width can be created in the same way as with integers. A precision (number
of decimal places after the decimal point) can be specified by putting a point after the
field width and a number of decimal places after that. For example %5.2lf will
output a double with a field width of 5 spaces and a precision of two digits. It is
possible to specify precision without a field with, for example %.2lf.
The following call outputs the value 1.23.
fprintf(outputStream, "%.2lf", 1.23456);
Field Width From a Variable or Constant

By placing an asterisk (*) in place of the field width, eg. %*i will cause fprintf()
to source the field width from the next argument which will precede the value to be
output in place of the format sequence. For example, if COLUMN_WIDTH was defined
as the width of columns in a table, the value of int variable columnValue can
output as follows.
fprintf(outputStream, "%*i", COLUMN_WIDTH, columnValue);
Format Flags

Within the specified filed width the following controls can be added.
-

left justify

force printing sign

0 (zero) pads field width with spaces


The following call outputs 005.
fprintf(outputStream, "%03i", 5);

CSC1402 Foundation Computing

A1.10

Escape Sequences
Some characters cannot be created in a format string using the normal keyboard.
\a

alert (bell sound)

\b

backspace

\f

formfeed

\n

newline

\r

carriage return

\t

tab

\"

double quotes

\\

backslash

The following call outputs "hello" (including the quotes).


fprintf(outputStream, "\"hello\"");
int fputc (char characterToOutput, FILE *stream);
Writes the character characterToOutput to stream. Returns the character
written if successful or EOF if unsuccessful.
The following call outputs a letter X.
fputc('X',outputStream);
int fputs (const char *stringToOutput, FILE *stream);
Writes the string stringToOutput to stream. Returns a non-negative (zero or
positive) number if successful or EOF if unsuccessful.
The following call outputs a the string hello.
fputs("hello",outputStream);
int fscanf (FILE *stream, const char *format, ...);
Reads from stream according to format and attempts to assign values described in
format by format sequences starting with % to the variables pointed to by the third
and following arguments. If an item read in does not match a format sequence given
the function will not assign a value and will stop attempting further input.
Characters in the format string that are not part of a format sequence are used to
describe the exact format of input expected. If the format does not match input given
the function will stop and not attempt further input.
Returns the number of correctly matched, read and assigned values. If fscanf()
stops before the end of the format string, the number of assigned values to that point
is returned.

CSC1402 Foundation Computing

The following call inputs an integer into inputInteger.


fscanf(outputStream, "%i", &inputInteger);
Format Sequences
The following format sequences are used with expressions of specific types.
%c

char

%i or %d

int

%s

string

%u

unsigned int

%li or %D

long int

%lu or %U

long unsigned int

%hi

short int

%hu

short unsigned int

%f

float

%lf

double

%L

long double

%%

percentage symbol

A1.11

CSC1402 Foundation Computing

A1.12

Scansets
A scanset allows us to specify exactly which characters we wish to allow or disallow
when reading in a string. Scansets can only be applied in place of an s format
specifier in a %s format sequence. It cannot be used to read in numbers or single
characters. Instead of an s we place a set bounded by two [ square brackets ]
containing the letters we will accept when reading into a string.
fscanf(inputStream, "%[abc]", myString);
In the above call to fscanf() a string is being read in. Only the characters a, b or
c will be accepted. When any other character is encountered, no further characters
will be read into myString.
A negated scanset specifies what characters will not be accepted when reading a
string. A negated scanset starts with a caret (^). The remaining characters form the
set of characters that will not be accepted. When reading in a string, all characters
(including whitespace characters) will be accepted until one of the characters in the
negated scanset is encountered.
fscanf(inputStream, "%[^abc]", myString);
A practical application for a negated scanset is when reading in a line of text. By
allowing all characters except the newline character, input into a string will continue
until the end of a line is encountered.
fscanf(inputStream, "%[^\n]", myString);
We should always restrict the length of a string read in using a scanset in the same
way that we do for a normal %s format sequence (by placing an length in between the
% and the scanset). The following call to fscanf() will read characters into
myString until a newline character is met, or 19 characters have been read in.
fscanf(inputStream, "%19[^\n]", myString);
Ignoring Input
Placing an asterisk (*) in a format sequence will cause a value to be input but not
stored. For example to read in and ignore a character between two integers the
following call can be used. Note that the surrounding, non-ignored inputs correspond
to addresses given as subsequent arguments.
fscanf(inputStream, "%i%*c%i", &firstInt, &secondInt);
Whitespace
Whitespace includes spaces, tabs carriage returns and newline characters. When
reading any basic type, except single characters or scansets that allow whitespace,
whitespace is skipped before usable input.
Ignoring Whitespace

When reading single characters or scansets that allow whitespace, or to explicitly


ignore whitespace at other times, any amount of whitespace can be ignored by

CSC1402 Foundation Computing

A1.13

including a single space character in a format sequence. For this reason \n, \t and
\r characters are not normally used in input format strings.
int getc (FILE *stream);
Achieves fgetc(stream).
int getchar (void);
Achieves fgetc(stdin).
int printf (const char *format, ...);
printf(format,args) achieves fprintf(stdout,format,args).
int putc (int characterToBeOutput, FILE *stream);
Achieves fputc(characterToBeOutput, stream).
int putchar (int characterToBeOutput);
putchar(characterToBeOutput) achieves
fputc(characterToBeOutput,stdout).
int puts (const char *stringToOutput);
Writes the string stringToOutput to stdout, and appends a newline. Returns
non-negative (zero or positive) for success or EOF for failure.
The following call outputs hello to standard output.
puts("hello");
int remove (const char *filename);
Deletes the file filename. Returns zero on success or non-zero on failure.
The following call deletes the file input.txt.
remove("input.txt");
int rename (const char *oldName, const char *newName);
Renames oldName to newName. Returns zero on success, non-zero on failure.

CSC1402 Foundation Computing

A1.14

The following call renames the file input.txt to become newInput.txt.


rename("input.txt","newInput.txt");
void rewind (FILE *stream);
Moves stream to the beginning of the file.
int scanf (const char *format, ...);
scanf(format,args) achieves fscanf(stdin,format,args).
int sprintf (
char *strToPrintTo,
const char *format,
...
);
Using the same functionality as fprintf(), but prints to strToPrintTo instead
of an output stream.
The following call builds a string with content "a string 5" (without quotes).
char stringToPrintTo[256];
sprintf(stringToPrintTo, "%s %i", "a string", 5);
int sscanf (
const char *strToRead,
const char *format,
...
);
Using the same functionality fscanf(), but 'reads' from strToRead instead of a
file.
The following call reads a string and an integer from stringToRead.
char stringToReadFrom = "string 5";
char stringToStore[256];
int integerToStore;
sscanf(
stringToReadFrom,
"%s %i",
stringToStore,
&integerToStore
);
int ungetc (int characterToPutBack, FILE *stream);
Puts the character characterToPutBack back into the input stream stream so
that it is the next character to be read in from the stream. Returns the character pushed
back if successful or EOF on failure.

CSC1402 Foundation Computing

A1.15

A1.4. String Conversion, Random Numbers and Other <stdlib.h>


void abort (void);
Ends the program and returns an unsuccessful termination program exit status.
int abs (int positiveOrNegativeInteger);
Returns the absolute value of positiveOrNegativeInteger.
positiveOrNegativeInteger is negative a positive equivalent is returned.

If

The following call outputs 5.


printf("%i\n", abs(-5));
double atof (const char *stringContainingNumber);
Returns the double equivalent of the number found at the beginning of the
stringContainingNumber. This function cannot be assume to work when nonnumeric data is present in the string.
The following call assigns 1.23 to numberFromString.
numberFromString = atof("1.23");
int atoi (const char *stringContainingNumber);
Returns the int equivalent of the number found at the beginning of the
stringContainingNumber. This function cannot be assume to work when nonnumeric data is present in the string.
The following call assigns 1 to numberFromString.
numberFromString = atoi("1");
long int atol (const char *stringContainingNumber);
Returns the long int equivalent of the number found at the beginning of the
stringContainingNumber. This function cannot be assume to work when nonnumeric data is present in the string.
The following call assigns 1234567 to numberFromString.
numberFromString = atoi("1234567");
void exit (int status);
Terminates the program returning status as the success status of the program (use
zero or EXIT_SUCCESS to indicate successful termination or a positive number or
EXIT_FAILURE for failure).

CSC1402 Foundation Computing

A1.16

The following call terminates the program and sets the termination status to 1.
exit(1);
int rand (void);
Returns a pseudo-random number in the range 0 to RAND_MAX (which is at least
32767 but usually 2147483647). A random sequence should be seeded using
srand() before using rand().
The following call generates a random integer and stores it in randomInteger.
randomInteger = rand();
The following call generates a random integer between 1 and 10.
randomInteger = rand()%10+1;
void srand (unsigned int seed);
Seeds a random sequence to be used by rand(). To produce a more unpredictable
random sequence the seed should be taken from a source of information outside the
computer, for instance the time that the user starts the program as shown below.
srand(time(NULL));

CSC1402 Foundation Computing

A1.17

A1.5. String Handling <string.h>


The type size_t is equivalent to an unsigned integer and used to indicate a number
of bytes. A single ASCII character occupies a single byte of memory so size_t is
also used to measure a number of characters.
char *strcat (char *strToCatTo, const char *strToCat);
Concatenates a copy of strToCat onto the end of strToCatTo. You should check
there is sufficient space in strToCatTo before performing the concatenation.
The following call concatenates " world" to the string in stringToAddTo.
char stringToAddTo[256] = "hello";
strcat(stringToAddTo, " world");
char *strncat (
char * strToCatTo,
const char * strToCat,
size_t numCharsToCat
);
Concatenates a copy of the first numCharsToCat of strToCat onto the end of
strToCatTo. You should check there is sufficient space in strToCatTo before
performing the concatenation.
char *strcpy (char *destination, const char *source);
Copies a string from source to destination. You should check there is
sufficient space in destination before performing the copy.
The following call replaces the string in stringToCopyTo with "hello world".
char stringToCopyTo[256] = "initial string content";
strcpy(stringToCopyTo, "hello world");
char *strncpy (
char *destination,
const char *source,
size_t numCharsToCopy
);
Copies the first numCharsToCopy from from source to destination. You
should check there is sufficient space in destination before performing the copy.

CSC1402 Foundation Computing

A1.18

int strcmp (const char *string1, const char *string2);


Compares the string string2 with the string string1. Returns...
0

where the two strings contain the same characters

<0

where the first different character is less in string1 than in string2

>0

where the first different character is greater in string1 than in string2

The difference for unequal strings is the difference in the ASCII codes of the first
different characters.
The following statement compares string1 and string2 to see if they contain the
same string.
if(strcmp(string1,string2)==0) { ...
int strncmp (
const char *string1,
const char *string2,
size_t numCharsToCompare
);
Compares the first numCharsToCompare characters string1 and string2
using the same method of comparison as for strcmp().
char *strchr (const char *strToSearch, int charToFind);
Returns the address of (a pointer to) the first occurrence of charToFind in the
string strToSearch. If the character is not found NULL is returned.
The following call finds the address of (a pointer to) 'c' in stringToSearch;
char *locationOfChar;
locationOfChar = strchr(stringToSearch, 'c');
The following statement tests if 'c' is in stringToSearch;
if(strchr(stringToSearch,'c')!=NULL) { ...
char *strrchr (const char * strToSearch, int charToFind);
Returns the address of (a pointer to) the last occurrence (the first from the right) of
charToFind in the string strToSearch. If the character is not found NULL is
returned.
char *strstr (
const char *strToSearch,
const char *subStrToFind
);
Returns the address of (a pointer to) the first occurrence of subStrToFind in the
string strToSearch. If the substring is not found NULL is returned.

CSC1402 Foundation Computing

A1.19

The following call finds the address of (a pointer to) "abc" in stringToSearch;
char *locationOfSubstr;
locationOfSubstr = strstr(stringToSearch, "abc");
The following statement tests "abc" is in stringToSearch;
if(strstr(stringToSearch, "abc")!=NULL) { ...
size_t strlen (const char *stringToMeasure);
Returns the length of the string stringToMeasure. This is the number of
characters before (not including) the null at the end of the string.
The following statement outputs the length of stringToMeasure.
printf("%i\n", strlen(stringToMeasure));

CSC1402 Foundation Computing

A1.20

A1.6. Date and Time <time.h>


The type time_t is used to store a number seconds since epoch (1/1/1970); this is
referred to as Unix time. It is useful to store time in this format as it is easily
compared and used in calculations. The structure type tm is provided to allow time
information to be represented in a form useful to humans. Some functions for
translating to and from these two forms are provided below.
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;

//
//
//
//
//
//
//
//
//
//
//
char *__tm_zone; //
int __tm_gmtoff; //

Seconds 0-59
Minutes 0-59
Hours 0-23
Day of month 1-31
Month of year 0-11
Years since 1900 (eg 2006=106)
Day of week (Sun=0 Sat=6)
Day of year (0-366)
Daylight savings flag (0 if
in not effect, >0 if in
effect, <0 if unknown)
Timezone string (start is 2 _s)
Offset to GMT (start 2 _s)

};
char *asctime (const struct tm *timeStructPtr);
Returns a pointer to a string containing the time indicated by the information in the
tm structure pointed to by timeStructPtr using the following standard format.
Day Mon DD HH:mm:ss YYYY\n
For example
Sat Oct 21 23:59:59 2006\n
The following outputs the current time in the standard format.
time_t currentUnixTime = time();
printf("%s", asctime(localtime(&currentUnixTime)));
struct tm *localtime (const time_t *timePtr);
Returns a pointer to a structure containing time information according to the time
given in the variable pointed to by timePtr.

CSC1402 Foundation Computing

A1.21

The following call creates a time structure with the current time information.
time_t currentUnixTime = time();
tm currentTimeStruct = *localtime(&currentUnixTime);
time_t mktime (struct tm *timeStructPtr);
Returns a Unix time of type time_t based on the information in the structure
variable pointed to by timeStructPtr. The first six members of the tm structure
(tm_sec, tm_min, tm_hour, tm_mday, tm_mon and tm_year) should and this
function will fill in the remaining members of the structure. Time-zone information is
gathered from the operating system.
The following call creates a Unix time from a structure containing time information.
time_t unixTime = mktime(&timeStruct);
time_t time (time_t *timePtr);
Returns the current Unix time. If timePtr is not NULL the time is also assigned to
the variable this points to. Returns -1 if time is not available.
The following outputs the current Unix time.
printf("%u\n", time(NULL));
size_t strftime (
char *stringToWriteTimeTo,
size_t capacityOfString,
const char *format,
const struct tm *timeStructPtr
);
Creates a string from a time structure (pointed to by timeStructPtr) according to
a specified format. The string is stored in stringToWriteTimeTo and will
limit the string length to capacityOfString characters.

CSC1402 Foundation Computing

A1.22

Format Sequences
The following format sequences can be used to describe the time format.
%a

abbreviated weekday name

%A

Full weekday name (Sunday, Monday)

%b or %h

Abbreviated month name (Sun, Mon, )

%B

Full month name (January, February, )

%c, %x or %X Locale appropriate date and time representation


%d

Day of the month (01 to31)

%D

Equivalent to %m / %d / %y

%e

Day of the month (1 to 31); a single digit is preceded by a space

%F

Equivalent to %Y - %m - %d

%H

Hour (24-hour clock) (00 to 23)

%I

Hour (12-hour clock) (01 to 12)

%j

Day of the year (001 to 366)

%m

Month (01 to 12)

%M

Minute (00 to 59)

%n

A newline character

%p

locale equivalent of either a.m. or p.m.

%r

Equivalent to %I : %M : %S %p

%R

Time in 24 hour representation %H : %M

%S

Second (00 to 59)

%t

Replaced by a tab character

%T

Equivalent to %H : %M : %S

%u

Weekday (1 to 7 where 1 represents Monday)

%U

Week of year (00 to 53) first Sunday in January is start of week 01

%w

Weekday (0 to 6 where 0 represents Sunday)

%W

Week of year (00 to 53) first Monday in January is start of week 01

%y or %C

Last two digits of year (00 to 99)

%Y

Year (eg 2006)

%z

Offset from UTC (+hhmm or hhmm) (eg., "-0430" means 4 hours 30


minutes behind UTC (west of Greenwich))

%Z

Time-zone name or abbreviation

%%

Percentage symbol

CSC1402 Foundation Computing

The following outputs the current time in the specified format.


char stringForTime[256];
time_t currentUnixTime = time(NULL);
strftime(
stringForTime,
256,
"%A %e %B, %Y %r",
localtime(&currentUnixTime)
);
printf("%s\n", stringForTime);

A1.23

CSC1402 Foundation Computing

A1.24

A1.7. Reserved Words


and

and_eq

asm

auto

bitand

bitor

bool

break

case

catch

char

class

const

const_cast continue

default

delete

do

double

dynamic_cast

else

enum

explicit

export

extern

false

float

for

friend

goto

if

inline

int

long

mutable

namespace

new

not

not_eq

operator

or

or_eq

private

protected

public

register

reinterpret_cast return

short

signed

sizeof

static

static_cast struct

switch

template

this

throw

true

try

typedef

typeid

typename

union

unsigned

using

virtual

void

volatile

wchar_t

while

xor

xor_eq

CSC1402 Foundation Computing

A1.8. ASCII Table


Code
0
7
8
9
10
13
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

Character
null \0
bell sound \a
backspace \b
horizontal tab \t
newline \n
carriage return \r
space
!
"
#
$
%
&
'
(
)
*
+
,
.
/
0
1
2
3
4
5
6
7
8
9
:
;
<

Code
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

Character
=
>
?
@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
[
\
]
^
_

Code
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

Character
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
{
|
}
~

A1.25

CSC1402 Foundation Computing

A1.26

Standard Library Index


abort.............................................................. 15
abs................................................................. 15
Absolute value of
floating point numbers ............................... 5
integers .................................................... 15
All functions
abort ......................................................... 15
abs ............................................................ 15
asctime ..................................................... 20
atof ........................................................... 15
atoi ........................................................... 15
atol ........................................................... 15
ceil ............................................................. 5
cos .............................................................. 5
exit ........................................................... 15
exp ............................................................. 5
fabs ............................................................ 5
fclose.......................................................... 7
feof ............................................................. 7
fgetc ........................................................... 7
fgets ........................................................... 7
floor ........................................................... 5
fopen .......................................................... 8
fprintf ......................................................... 8
fputc ......................................................... 10
fputs ......................................................... 10
fscanf ....................................................... 10
getc .......................................................... 13
getchar ..................................................... 13
isalnum ...................................................... 3
isalpha ........................................................ 3
isdigit ......................................................... 3
islower ....................................................... 3
isspace........................................................ 4
isupper ....................................................... 4
localtime .................................................. 20
log .............................................................. 5

log10 .......................................................... 5
mktime ..................................................... 21
pow. ............................................................ 6
printf ......................................................... 13
putc ........................................................... 13
putchar ...................................................... 13
puts ........................................................... 13
rand .......................................................... 16
remove ...................................................... 13
rename ...................................................... 13
rewind....................................................... 14
scanf ......................................................... 14
sin. .............................................................. 6
sprintf ....................................................... 14
sqrt.............................................................. 6
srand ......................................................... 16
sscanf........................................................ 14
strcat ......................................................... 17
strchr ........................................................ 18
strcmp ....................................................... 18
strcpy ........................................................ 17
strftime ..................................................... 21
strlen ......................................................... 19
strncat ....................................................... 17
strncmp ..................................................... 18
strncpy ...................................................... 17
strrchr ....................................................... 18
strstr.......................................................... 18
tan ............................................................... 6
time .......................................................... 21
tolower ....................................................... 4
toupper ....................................................... 4
ungetc ....................................................... 14
ASCII Table .................................................. 25
asctime .......................................................... 20
atof ................................................................ 15
atoi ................................................................ 15

CSC1402 Foundation Computing

A1.27

atol ................................................................ 15

From a variable or constant ........................ 9

ceil .................................................................. 5

Integers, strings and single characters ........ 9

Character Functions ........................................ 3

File functions .................................................. 7

isalnum ...................................................... 3

fclose .......................................................... 7

isalpha ........................................................ 3

feof ............................................................. 7

isdigit ......................................................... 3

fopen .......................................................... 8

islower ....................................................... 3

Files

isspace........................................................ 4

Closing ....................................................... 7

isupper ....................................................... 4

Deleting .................................................... 13

tolower ....................................................... 4

Detecting end of file ................................... 7

toupper ....................................................... 4

Opening ...................................................... 8

Check if character is

Renaming ................................................. 13

a letter ........................................................ 3

floor................................................................. 5

a letter or digit............................................ 3

fopen ............................................................... 8

a lower case letter ...................................... 3

Format Sequences

a numeric digit ........................................... 3

date and time ............................................ 22

a whitespace character ............................... 4

Input ........................................................... 8

an upper case letter .................................... 4

Output ...................................................... 11

Convert a letter to

fprintf .............................................................. 8

a lower case letter ...................................... 4

fputc .............................................................. 10

an upper case letter .................................... 4

fputs .............................................................. 10

Converting

fscanf............................................................. 10

string to floating point number ................ 15

getc ................................................................ 13

string to integer ........................................ 15

getchar ........................................................... 13

string to long integer ................................ 15

Ignoring input ............................................... 12

to time structure ....................................... 20

Input

to Unix time ............................................. 21

All types ................................................... 10

cos................................................................... 5

Controlled string....................................... 12

EOF ................................................................ 7

From standard input ................................. 14

Escape sequences ......................................... 10

Ignoring .................................................... 12

exit ................................................................ 15

Ignoring Whitespace ................................ 12

exp .................................................................. 5

Scansets .................................................... 12

fabs ................................................................. 5

Single character .................................... 7, 13

fclose .............................................................. 7

Strings ........................................................ 7

feof ................................................................. 7

Whitespace ............................................... 12

fgetc ................................................................ 7

Input functions ................................................ 7

fgets ................................................................ 7

fgetc............................................................ 7

Field Width ..................................................... 9

fgets ............................................................ 7

Floating point numbers .............................. 9

fscanf ........................................................ 10

Format flags ............................................... 9

getc ........................................................... 13

CSC1402 Foundation Computing

A1.28

getchar ..................................................... 13

printf ..................................................... 8, 13

rewind ...................................................... 14

putc ........................................................... 13

scanf ......................................................... 14

putchar ...................................................... 13

ungetc ...................................................... 14

puts ........................................................... 13

isalnum ........................................................... 3

rewind....................................................... 14

isalpha............................................................. 3

pow ................................................................. 6

isdigit .............................................................. 3

Power .............................................................. 6

islower ............................................................ 3

printf ............................................................. 13

isspace ............................................................ 4

Programs

isupper ............................................................ 4

Terminating .............................................. 15

localtime ....................................................... 20

putc ............................................................... 13

log ................................................................... 5

putchar .......................................................... 13

log10 ............................................................... 5

puts ................................................................ 13

Mathematical functions .................................. 5

rand ............................................................... 16

abs ............................................................ 15

Random number functions

ceil ............................................................. 5

rand .......................................................... 16

cos .............................................................. 5

srand ......................................................... 16

exp ............................................................. 5

Random numbers

fabs ............................................................ 5

getting....................................................... 16

floor ........................................................... 5

seeding ..................................................... 16

log .............................................................. 5

remove .......................................................... 13

log10 .......................................................... 5

rename ........................................................... 13

pow. ........................................................... 6

Reserved words ............................................. 24

sin. ............................................................. 6

rewind ........................................................... 14

sqrt ............................................................. 6

Rounding numbers

tan .............................................................. 6

down ........................................................... 5

mktime .......................................................... 21

up................................................................ 5

Output

scanf .............................................................. 14

All types ..................................................... 8

Scanset .......................................................... 12

Backslash ................................................. 10

sin 6

Newline .................................................... 10

sprintf ............................................................ 14

Quotes ...................................................... 10

sqrt .................................................................. 6

Single character ................................. 10, 13

Square Root..................................................... 6

String ................................................. 10, 13

srand .............................................................. 16

Tab ........................................................... 10

sscanf ............................................................ 14

Time ................................................... 20, 21

strcat .............................................................. 17

To standard output ................................... 13

strchr ............................................................. 18

Output functions ............................................. 7

strcmp ........................................................... 18

fputc ......................................................... 10

strcpy............................................................. 17

fputs ......................................................... 10

strftime .......................................................... 21

CSC1402 Foundation Computing

A1.29

String functions ............................................ 17

strstr .............................................................. 18

sprintf ....................................................... 14

tan ................................................................... 6

sscanf ....................................................... 14

Terminating ................................................... 15

strcat ........................................................ 17

time ............................................................... 21

strchr ........................................................ 18

Time

strcmp ...................................................... 18

Converting .......................................... 20, 21

strcpy ....................................................... 17

Getting current ..................................... 21

strlen ........................................................ 19

Output ................................................ 20, 21

strncat ...................................................... 17

struct tm.................................................... 20

strncmp .................................................... 18

time_t ....................................................... 20

strncpy ..................................................... 17

Time functions .............................................. 20

strrchr ....................................................... 18

asctime ..................................................... 20

strstr ......................................................... 18

localtime ................................................... 20

Strings

mktime ..................................................... 21

Adding to end .......................................... 17

strftime ..................................................... 21

Assigning ................................................. 17

time .......................................................... 21

Comparing ............................................... 18

tolower ............................................................ 4

Concatenating .......................................... 17

toupper ............................................................ 4

Constructing from parts ........................... 14

Trigonometric functions

Copying ................................................... 17

cos .............................................................. 5

Deconstructing to parts ............................ 14

sin. .............................................................. 6

Finding characters in ............................ 18

tan ............................................................... 6

Finding substrings in ............................ 18

Types

Length of.............................................. 19

size_t ........................................................ 17

strlen ............................................................. 19

struct tm.................................................... 20

strncat ........................................................... 17

time_t ....................................................... 20

strncmp ......................................................... 18

ungetc ............................................................ 14

strncpy .......................................................... 17

Whitespace .................................................... 12

strrchr ........................................................... 18

Ignoring .................................................... 12

Você também pode gostar