Assignment name : aff_a
Expected files : aff_a.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that takes a string, and displays the first 'a' character it
encounters in it, followed by a newline. If there are no 'a' characters in the
string, the program just writes a newline. If the number of parameters is not
1, the program displays 'a' followed by a newline.
Example:
$> ./aff_a "abc" | cat -e
a$
$> ./aff_a "dubO a POIL" | cat -e
a$
$> ./aff_a "zz sent le poney" | cat -e
$
$> ./aff_a | cat -e
a$
#include <unistd.h>
int main(int argc, char*argv[])
{
int c;
c = 0;
if (argc == 2)
{
while(argv[1][c] != '\0')
{
if (argv[1][c] == 'a')
{
write(1,"a\n",2);
break;
}
else
{
write(1,"\n",1);
break;
}
c++;
}
}
else
write(1,"a\n",2);
return (0);
}
Assignment name : aff_first_param
Expected files : aff_first_param.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that takes strings as arguments, and displays its first
argument followed by a \n.
If the number of arguments is less than 1, the program displays \n.
Example:
$> ./aff_first_param vincent mit "l'ane" dans un pre et "s'en" vint | cat -e
vincent$
$> ./aff_first_param "j'aime le fromage de chevre" | cat -e
j'aime le fromage de chevre$
$> ./aff_first_param
$
#include <unistd.h>
int main(int argc, char*argv[])
{
int c;
c = -1;
if (argc > 1)
{
while(argv[1][++c])
write(1,&(argv[1][c]),1);
}
write(1,"\n",1);
return (0);
}
Assignment name : aff_last_param
Expected files : aff_last_param.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that takes strings as arguments, and displays its last
argument followed by a newline.
If the number of arguments is less than 1, the program displays a newline.
Examples:
$> ./aff_last_param "zaz" "mange" "des" "chats" | cat -e
chats$
$> ./aff_last_param "j'aime le savon" | cat -e
j'aime le savon$
$> ./aff_last_param
$
#include <unistd.h>
int main(int argc, char*argv[])
{
int c;
c = -1;
if (argc > 1)
{
while(argv[argc-1][++c])
write(1,&(argv[argc-1][c]),1);
}
write(1,"\n",1);
return (0);
}
Assignment name : aff_z
Expected files : aff_z.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that takes a string, and displays the first 'z'
character it encounters in it, followed by a newline. If there are no
'z' characters in the string, the program writes 'z' followed
by a newline. If the number of parameters is not 1, the program displays
'z' followed by a newline.
Example:
$> ./aff_z "abc" | cat -e
z$
$> ./aff_z "dubO a POIL" | cat -e
z$
$> ./aff_z "zaz sent le poney" | cat -e
z$
$> ./aff_z | cat -e
z$
#include <unistd.h>
int main(int argc, char*argv[])
{
(void) argc;
(void) argv;
write(1,"z\n",2);
return (0);
}
Assignment name : ft_countdown
Expected files : ft_countdown.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that displays all digits in descending order, followed by a
newline.
Example:
$> ./ft_countdown | cat -e
9876543210$
$>
#include <unistd.h>
int main()
{
int i;
i = '9';
while (i >= '0')
{
write(1, &i , 1);
i--;
}
write(1, "\n", 1);
return (0);
}
Assignment name : ft_print_numbers
Expected files : ft_print_numbers.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a function that displays all digits in ascending order.
Your function must be declared as follows:
void ft_print_numbers(void);
#include <unistd.h>
void ft_print_numbers(void)
{
int i;
i = '0';
while (i <= '9')
{
write(1, &i, 1);
i++;
}
write(1, "\n", 1);
}
Assignment name : hello
Expected files : hello.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that displays "Hello World!" followed by a \n.
Example:
$>./hello
Hello World!
$>./hello | cat -e
Hello World!$
$>
#include <unistd.h>
int main()
{
write(1, "Hello World!\n", 13);
return (0);
}
Assignment name : maff_alpha
Expected files : maff_alpha.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that displays the alphabet, with even letters in uppercase, and
odd letters in lowercase, followed by a newline.
Example:
$> ./maff_alpha | cat -e
aBcDeFgHiJkLmNoPqRsTuVwXyZ$
#include <unistd.h>
int main()
{
char odd_c = 'a';
char even_c = 'B';
while (even_c <= 'Z')
{
write(1, &odd_c, 1);
write (1, &even_c, 1);
even_c += 2;
odd_c += 2;
}
write(1, "\n", 1);
return (0);
}
Assignment name : maff_revalpha
Expected files : maff_revalpha.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that displays the alphabet in reverse, with even letters in
uppercase, and odd letters in lowercase, followed by a newline.
Example:
$> ./maff_revalpha | cat -e
zYxWvUtSrQpOnMlKjIhGfEdCbA$
#include <unistd.h>
int main()
{
char odd_c = 'z';
char even_c = 'Y';
while (even_c >= 'A')
{
write(1, &odd_c, 1);
write (1, &even_c, 1);
even_c -= 2;
odd_c -= 2;
}
write(1, "\n", 1);
return (0);
}
Assignment name : only_a
Expected files : only_a.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that displays a 'a' character on the standard output.
#include <unistd.h>
int main()
{
write(1, "a", 1);
return (0);
}
Assignment name : only_z
Expected files : only_z.c
Allowed functions: write
--------------------------------------------------------------------------------
Write a program that displays a 'z' character on the standard output.
#include <unistd.h>
int main()
{
write(1, "z", 1);
return (0);
}