This page contains some elemntary examples and problems for the Systems Programming course. More and a bit more challenging exercises are available in this collection of exam problems.
wc -w
.
# ### ##### ####### ######### ########### ######### ####### ##### ### #
'#'
) up to the end of line, including the new-line
character ('\n'
). The output should be the same as
the command:
sed -n -e 's/^[^#]*#//p'
ciao
, the
program should output oaic
. Notice that the output
must have exactly the same number of lines as the input. In
particular, If an input line is terminated by a newline character
('\n'
), then the output line should also be
terminated by a newline character. Otherwise, if the input line
is terminated by the end of file, then the output line should also
terminate the file directly (without a newline character).
You may assume that lines are at most 1000 characters long (bytes).
int line_to_args (char * argv[], int max_count, char *
line)
that takes an argument vector argv of maximal
length max_count and a string line containing a
sequence of zero or more arguments separated by one or more space
characters. The function must parse the input line, change the
line, and set the argv vector to point to all the component
arguments. The return value is the total number of arguments read
and set in argv, which must always be less than or equal
to max_count. For example, with a line "one two
three"
and an argument vector of at most 10 elements, the
result is 3 and the 3 arguments
are "one"
, "two"
,
and "three"
, respectively. You must nt allocate
additional memory. You may not use any external library function,
not even from the C standard library.
void sort_strings(const char * input, char * output, unsigned
int n)
that takes a sequence of n≤1000 contiguous
C strings from a given input memory buffer, and copies in a
given output buffer the same strings, also as a sequence of
contiguous C strings, but sorted in non-decreasing lexicographical
order. The order is defined by the numerical order of the character
codes. Do not worry too much about the complexity of your sorting
algorithm. You may not use any external library function, not even
from the C standard library.
int twotimes(const char *s)
and
int twotimes2(const char *begin, const char *end)
, that
return true (non zero) if the string passed as argument
consists of the concatenation of two identical strings,
or false (zero) otherwise. The twotimes
function takes a C-string, meaning a zero-terminated string.
The twotimes2
function takes any sequence of chars
defined by a pointer to the first character (begin) and a
pointer to first character past the end of the string
(end). You may not use any external library function, not
even from the C standard library.
int redact_digits(char *s)
in a C source
file called redactdigits.c that modifies the string
passed as input so as to redact the appearence of every digit in
the string. Redacting means replacing every digit with the hash
mark ('#'
). The return value must be 1
if the input string was modified, or 0
otherwise.
int delete_digits(char *s)
in a C source
file called deletedigits.c that modifies the string
passed as input so as to delete every digit in the string. The
return value must be 1
if the input string was
modified, or 0
otherwise.
10 20 blue 15 15 green 12 8 redthe output must be
greenIf there are two or more maximal rectangles, then the program should output the color of the first one. You may not use any external library function other than the input functions from the C standard library.
int contains_str(const char * s, const char * x)
The contains_str function must return true (non
zero) if and only if the string s contains the
string x. You may not use any external library function,
not even from the C standard library.
int concatenate(char * s, unsigned max_size, const char * s2)
The concatenate function must concatenate the string s2
to the string s making sure that the resulting string s
does not contain more than max_size characters, including the
terminator character. The concatenate function must return
true (non zero) if and only if it concatenated the full
second string s2 without exceeding the max_size
limit. You may not use any external library function,
not even from the C standard library.
int contains_double(const char * s)
The contains_double function must return true (non zero)
if and only if the string s contains two identical non-empty strings
separated by a hyphen character (-
). For example,
contains_double("there are no hyphens in this string")
should
return false and also contains_double("a-b")
should
return false, while contains_double("012-012!")
should
return true. You may not use any external library function,
not even from the C standard library.