Skip to content

Commit

Permalink
Tp2
Browse files Browse the repository at this point in the history
  • Loading branch information
chaminaud committed Nov 24, 2018
0 parents commit 6f441c2
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TP2
22 changes: 22 additions & 0 deletions ex0.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "tp2.h"
#include <string.h>
#include <stdio.h>





int main(int argc, char *argv[])
{

char *chaine=get_first_arg(argc, argv);;
//print(upper(chaine));
//piramide(chaine);
//fractionate(argv);
return to_int(chaine);
}





Binary file added exe
Binary file not shown.
98 changes: 98 additions & 0 deletions tp2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

char *upper(char *s)
{
for (int i = 0; i < strlen(s); i++)
{

s[i] -= 32;
}

return s;
}

char *get_first_arg(int argc, char *argv[])
{
if (argc < 2)
{
printf("no argument\n\n");
exit(0);
}
return (argv[1]);
}

void print(char *chaine)
{
printf("%s", chaine);
}

void step1(char *chaine)
{

int size = strlen(chaine);
char tab[2 * size];
int j = 0;
while (j < size)
{
j++;
if (j == 1)
{
for (int i = 0; i < size; i++)
{
tab[size - i] = chaine[i];
tab[size + i] = chaine[i];
}
}
else
{
for (int k = 0; k < j; k++)
{
tab[k] = ' ';
tab[2 * size - k] = ' ';
}
for (int i = 0; i < size - j; i++)
{
tab[size - i] = chaine[i];
tab[size + i] = chaine[i];
}
}

printf("%s\n", tab);
}
}

void fractionate(char **chaine)
{

int j = 0;

while (chaine[j] != NULL)
{
j++;
}
int size = j;

for (int i = 1; i < size; i++)
{
chaine[i][0] -= 32;
printf("%s\n", chaine[i]);
}
}

void piramide(char *tab)
{
step1(tab);
}

int to_int(char *tab)
{
int size = strlen(tab);
int value=0;
for(int i=0;i<size-1;i++){
value+=tab[i];
}
return value;
}
16 changes: 16 additions & 0 deletions tp2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

char* upper(char *s);

void print(char * chaine);

char *get_first_arg(int argc, char *argv[]);

void print(char *chaine );

void step1(char *chaine );

void fractionate(char **chaine);

void piramide(char *chaine );

int to_int(char *tab);

0 comments on commit 6f441c2

Please sign in to comment.