B CPE 042 Day04 .pdf

À propos / Télécharger Aperçu
Nom original: B-CPE-042_Day04.pdf

Ce document au format PDF 1.5 a été généré par LaTeX with hyperref package / pdfTeX-1.40.16, et a été envoyé sur fichier-pdf.fr le 06/10/2016 à 17:50, depuis l'adresse IP 89.84.x.x. La présente page de téléchargement du fichier a été vue 869 fois.
Taille du document: 218 Ko (6 pages).
Confidentialité: fichier public

Aperçu du document

B1- C Pool

Day 04


Day 04
repository name: : CPool_Day04
repository rights: : ramassage-tek
language: : C
group size: : 1

• Your repository must contain the totality of your source files, but no useless files (binary, temp files,
obj files,...).
• Don’t push your main function into your delivery directory, we will be adding our own. Your files
will be compiled adding our main.c and our my_putchar.c files.
• You are only allowed to use the my_putchar function to complete the following tasks, but don’t
push it into your delivery directory, and don’t copy it in any of your delivered files.
• If one of your files prevents you from compiling with * .c, the Autograder will not be able to correct
your work and you will receive a 0.

Create your repository at the beginning of the day and submit your work on a regular basis!
The delivery directory is specified within the instructions for each task.
In order to keep your repository clean, pay attention to gitignore.


Task 0
Unit Tests
It is highly recommended to test your functions as you develop them. It is common practice to create a function
named main (and a designated file to host it) to check the functions separately.
Create a directory named tests.
Create a main function within a file named tests-$TASK.c, to be stored in the tests directory named.
This function must contain all the necessary calls to the task function in order to cover all of the function’s possible
situations (normal or irregular).

Task 1
Automated Exams
Open your weekly schedule in the intranet.
Register for Saturday’s exam.
Check that you are registered for Saturday’s exam.
—-> If you are not registered, go back to the previous step.
Double check that you are registered.
—-> If you aren’t, go back to previous step.
Are you registered for Saturday’s exam?
—-> If you are not, go back to first step.

Task 2
Write a function that swaps the content of two integers, whose addresses are given as parameter. It must be prototyped as follows:
i n t my_swap ( i n t * a , i n t * b ) ;

Delivery: CPool_Day04/my_swap.c


Task 3
Write a function that displays, one-by-one, the characters of a string.
The address of the string’s first character will be found in the pointer passed as a parameter to the function, which
must be prototyped as follows:
i n t my_putstr ( c h a r * s t r ) ;

Delivery: CPool_Day04/my_putstr.c

Task 4
Write a function that counts and returns the number of characters found in the string passed as parameter. It must
be prototyped as follows:
i n t my_strlen ( char * s t r ) ;

Delivery: CPool_Day04/my_strlen.c


Task 5
The goal of this task is to swap each of the string’s characters, two by two.
In other words, you will swap the first letter with the last one, the second with the second-to-last and so on.
The function should return a pointer to the first character of the reversed string:
char * my_evil_str ( char * s t r ) ;

Delivery: CPool_Day04/my_evil_str.c
For instance:
a => a
ab = > ba
abc = > cba
abcd = > dcba
abcde = > edcba
abcdef = > fedcba

With the following code, the str string is in ReadOnly mode. If you try to modify this string you will
get a segfault!

char * s t r ;
s t r = " toto " ;

In order to test your string, you will need to duplicate the string in ReadWrite mode using: strdup.

#i n c l u d e < s t r i n g . h >
main ( )



* str ;

s t r = strdup ( " toto " ) ;
my_evil_str ( s t r ) ;
my_putstr ( s t r ) ;
return (0) ;

For those who are curious: you will be coding your own strdup in a few days, so be patient!


Task 6
Write a function that returns a number, sent to the function as a string. It must be prototyped as follows:
i n t my_getnbr ( c h a r * s t r ) ;

Delivery: CPool_Day04/my_getnbr.c
Here are some tricky examples to be handled:
"+−−−+−−++−−−+−−−+−−−+−42" = > −42
" 42a43 " = > 42
"11000000000000000000000042" = > 0 ( t h e number doesn ’ t f i t i n an i n t e g e r )
"−1000000000000000000000042" = > 0 ( f o r t h e same r e a s o n }

Task 7
Bonus: my_sort_int_tab
Write a function that sorts an integer array in ascending order, given a pointer to the first element of the array and its
v o i d m y _ s o r t _ i n t _ t a b ( i n t * tab , i n t s i z e ) ;

Delivery: CPool_Day04/my_sort_int_tab.c


Aperçu du document B-CPE-042_Day04.pdf - page 1/6

Aperçu du document B-CPE-042_Day04.pdf - page 2/6

Aperçu du document B-CPE-042_Day04.pdf - page 3/6

Aperçu du document B-CPE-042_Day04.pdf - page 4/6

Aperçu du document B-CPE-042_Day04.pdf - page 5/6

Aperçu du document B-CPE-042_Day04.pdf - page 6/6

Télécharger le fichier (PDF)

Sur le même sujet..

Ce fichier a été mis en ligne par un utilisateur du site. Identifiant unique du document: 00456861.
⚠️  Signaler un contenu illicite
Pour plus d'informations sur notre politique de lutte contre la diffusion illicite de contenus protégés par droit d'auteur, consultez notre page dédiée.