commit a66c7b39959e803786af3946e3b8912e606d61eb
parent f0fa6fbd5a69595a6cef0cf1f318f87972f56d67
Author: Martin J. Klöckner <martin.cachari@gmail.com>
Date: Sun, 20 Dec 2020 00:47:30 -0300
Reorganized files & directories;
Diffstat:
72 files changed, 0 insertions(+), 2218 deletions(-)
diff --git a/95.11/clean.sh b/95.11/clean.sh
@@ -1,25 +0,0 @@
-#!/bin/bash
-
-# Removes every a.out from every subfolder where the
-# script is executed;
-
-# Set the filename;
-file='a.out'
-
-# The path where 'file' is gonna be looked for;
-subfolders=./**/$file
-currentdir=./$file
-
-# First checks if the file exist in the current directory
-# or in any sub-folder, if exist removes it from everywhere;
-if [ -e $currentdir ] || [ -e $subfolders ];
-then
- rm -v -f ./**/"$file"
- rm -v -f "$file"
- echo "everithing cleaned succesfully"
-
-# if doesn't exist then does nothing;
-else
- echo "everything seems clean"
- echo "there is nothing to do"
-fi
diff --git a/95.11/guia01/ej1.c b/95.11/guia01/ej1.c
@@ -1,39 +0,0 @@
-#include <stdio.h>
-
-#define DIVISA_NAME_ARS "Pesos"
-#define DIVISA_NAME_BRL "Reales"
-#define DIVISA_NAME_USD "Dolares"
-#define DIVISA_NAME_EUR "Euros"
-
-#define MAX_DIVISAS 4
-
-typedef enum {
- ARS, BRL, USD, EUR
-} divisa_t;
-
-
-int main( void ) {
-
- divisa_t divisa_origen = ARS;
- divisa_t divisa_final = USD;
-
- float monto_origen, monto_final;
-
- monto_origen = 1000;
-
-
-
- float divisas[MAX_DIVISAS][MAX_DIVISAS] = {
- {1.000, 0.067, 0.012, 0.011}, // ARS
- {0.067, 1.000, 0.190, 0.160}, // BRL
- {0.012, 0.190, 1.000, 0.850}, // USD
- {0.011, 0.160, 0.850, 1.000} // EUR
- };
-
- monto_final = (monto_origen * divisas[divisa_origen][divisa_final]);
- printf("%f\n", monto_final);
-
- return 0;
-}
-
-
diff --git a/95.11/guia01/ej2.c b/95.11/guia01/ej2.c
@@ -1,15 +0,0 @@
-/* Calculates the total resistance of a closed circuit */
-
-#include <stdio.h>
-
-#define MAX_RESISTORS 7
-
-int main( void ) {
-
- int resistor[MAX_RESISTORS];
-
-
-
-
- return 0;
-}
diff --git a/95.11/guia01/ej5.c b/95.11/guia01/ej5.c
@@ -1,27 +0,0 @@
-#include <stdio.h>
-#include <math.h>
-
-int main( void ) {
-
- float raiz = 25;
- float inv = 4;
-
- printf("sqrt(%.2f) = ", raiz);
-
- if(raiz > 0)
- raiz = sqrt(raiz);
- else
- return 1;
-
- printf("%.2f\n", raiz);
- printf("inv(%.2f) = ", inv);
-
- if (inv != 0)
- inv = 1/inv;
- else
- return 1;
-
- printf("%.2f\n", inv);
-
- return 0;
-}
diff --git a/95.11/guia01/ej6.c b/95.11/guia01/ej6.c
@@ -1,20 +0,0 @@
-#include <stdio.h>
-#include <math.h>
-
-
-int main( void ) {
-
- int a, b, c;
- float x1, x2;
-
- a = 1;
- b = -12;
- c = 36;
-
- x1 = ((-b) + sqrtf( (b*b)-(4*a*c) )) / (2*a);
- x2 = ((-b) - sqrtf( (b*b)-(4*a*c) )) / (2*a);
-
- printf("x1 = % .2f\nx2 = % .2f\n", x1, x2);
-
- return 0;
-}
diff --git a/95.11/guia01/ej8.c b/95.11/guia01/ej8.c
@@ -1,27 +0,0 @@
-/* Calculates the factorial of a given number. */
-
-#include <stdio.h>
-
-#define ERR_MSG_NEG "ERR: The entered number is negative!"
-
-int main(void) {
-
- int fact, i, res;
-
- printf("Enter a number: ");
- if(scanf("%i", &fact) == EOF)
- return 1;
-
- if(fact < 0) {
- printf(ERR_MSG_NEG"\n");
- return 1;
- }
-
- res = 1;
- for(i = 1; i <= fact; i++) {
- res *= i;
- }
-
- printf("%d! = %d\n", fact, res);
- return 0;
-}
diff --git a/95.11/guia02/ex01.c b/95.11/guia02/ex01.c
@@ -1,16 +0,0 @@
-#include <stdio.h>
-
-typedef enum {
- FALSE,
- TRUE
-} bool_t;
-
-int main(void)
-{
- bool_t isworking = TRUE;
- printf("%s\n", isworking ? "TRUE" : "FALSE");
-
- return 0;
-}
-
-
diff --git a/95.11/guia02/ex02.c b/95.11/guia02/ex02.c
@@ -1,21 +0,0 @@
-#include <stdio.h>
-
-typedef enum {
- ERROR,
- OK
-} status_t;
-
-int main(void)
-{
-
- status_t isworking = OK;
-
- if (isworking == 1)
- printf("OK\n");
- else
- printf("ERROR\n");
-
- return 0;
-}
-
-
diff --git a/95.11/guia02/ex03.c b/95.11/guia02/ex03.c
@@ -1,15 +0,0 @@
-#include <stdio.h>
-
-typedef enum {
- LUN, MAR, MIE, JUE, VIE, SAB, DOM
-} dia_t;
-
-int main(void)
-{
- dia_t dia = VIE;
-
- printf("%d\n", dia);
-
-
- return 0;
-}
diff --git a/95.11/guia02/ex04.c b/95.11/guia02/ex04.c
@@ -1,79 +0,0 @@
-/* Ejercicio 4 - Guia 2, Algoritmos y Programacion I - FIUBA */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_INP_LEN 10
-
-typedef enum {
- FAHRENHEIT,
- CELSIUS
-} escala_t;
-
-typedef float dato_t;
-
-dato_t ftoc(dato_t fahrenheit)
-{
- return (((fahrenheit - 32) *5 ) / 9);
-}
-
-dato_t ctof(dato_t celsius)
-{
- return (((celsius * 9) / 5) + 32);
-}
-
-void title(int i)
-{
- printf(
- "---------------------------------------\n"
- "---------------------------------------\n"
- "--- %s TO %s CONVERTER ---\n"
- "---------------------------------------\n"
- "--- to exit press Ctrl+D ----\n"
- "---------------------------------------\n"
- "---------------------------------------\n",
- i ? "CELSIUS" : "FAHRENHEIT",
- i ? "FAHRENHEIT" : "CELSIUS"
- );
-}
-
-void cursor()
-{
- printf(">> ");
-}
-
-
-
-int main(void)
-{
- char buffer[MAX_INP_LEN];
- escala_t c;
- dato_t i, res;
- printf("0 - FAHRENHEIT TO CELSIUS\n");
- printf("1 - CELSIUS TO FAHRENHEIT\n");
- cursor();
- c = getchar() - '0';
- if (c == FAHRENHEIT) {
- title(FAHRENHEIT);
- while (fgets(buffer, MAX_INP_LEN, stdin) != NULL) {
- i = atoi(buffer);
- res = ftoc(i);
- printf("%.0f°F = %.2f°C\n", i, res);
- cursor();
- }
- } else if (c == CELSIUS) {
- title(CELSIUS);
- while (fgets(buffer, MAX_INP_LEN, stdin) != NULL) {
- i = atoi(buffer);
- res = ctof(i);
- printf("%.0f°C = %.2f°F\n", i, res);
- cursor();
- }
- }
- printf("\n");
- return 0;
-}
-
-
-
diff --git a/95.11/guia02/ex05.c b/95.11/guia02/ex05.c
@@ -1,62 +0,0 @@
-#include <stdio.h>
-
-typedef enum {
- JAN, FEB, MAR, APR, MAY, JUN, JUL, AGO, SEP, OCT, NOV, DEC
-} mes_t;
-
-#define JANUARY "ENERO"
-#define FEBRUARY "FEBRERO"
-#define MARCH "MARZO"
-#define APRIL "ABRIL"
-#define MAYO "MAYO"
-#define JUNE "JUNIO"
-#define JULY "JULIO"
-#define AUGUST "AGOSTO"
-#define SEPTEMBER "SEPTIEMBRE"
-#define OCTOBER "OCTUBRE"
-#define NOVEMBER "NOVIEMBRE"
-#define DECEMBER "DICIEMBRE"
-
-int main(void) {
- mes_t mes = NOV;
- switch(mes)
- {
- case JAN:
- printf(JANUARY"\n");
- break;
- case FEB:
- printf(FEBRUARY"\n");
- break;
- case MAR:
- printf(MARCH"\n");
- break;
- case APR:
- printf(APRIL"\n");
- break;
- case MAY:
- printf(MAYO"\n");
- break;
- case JUN:
- printf(JUNE"\n");
- break;
- case JUL:
- printf(JULY"\n");
- break;
- case AGO:
- printf(AUGUST"\n");
- break;
- case SEP:
- printf(SEPTEMBER"\n");
- break;
- case OCT:
- printf(OCTOBER"\n");
- break;
- case NOV:
- printf(NOVEMBER"\n");
- break;
- case DEC:
- printf(DECEMBER"\n");
- break;
- }
- return 0;
-}
diff --git a/95.11/guia02/ex06.c b/95.11/guia02/ex06.c
@@ -1,27 +0,0 @@
-#include <stdio.h>
-#include <ctype.h>
-
-int main(void)
-{
- int alpha, nonalpha, num;
- int c;
-
- alpha = nonalpha = num = 0;
-
- while((c = getchar()) != EOF ) {
- if(isalpha(c))
- alpha++;
- else if(isdigit(c))
- num++;
- else if(!isalnum(c))
- nonalpha++;
- }
- printf(
- "Alphanumerics: %d\n"
- "NonAlphanumerics: %d\n"
- "Digits: %d\n",
- alpha, nonalpha, num
- );
-
- return 0;
-}
diff --git a/95.11/guia02/ex07.c b/95.11/guia02/ex07.c
@@ -1,62 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-#define MAX_LEN 5 // max digits of the entered degree;
-#define ERR_MSG_LEN "El angulo ingresado contiene demasiados digitos"
-
-typedef enum {
- AGUDO, OBTUSO, RECTO
-} angulo_t;
-
-
-void clean(char *buffer)
-{
- for(size_t i = 0; i < MAX_LEN; i++)
- buffer[i] = '\0';
-}
-
-
-int main(void) {
-
- char buffer[MAX_LEN];
- clean(buffer);
- int c, d, e, i;
- i = 0;
- while(((c = getchar()) != EOF) && c != '\n') {
- if(i < MAX_LEN) {
- buffer[i] = c;
- i++;
- } else if (i >= MAX_LEN) {
- fprintf(stderr, ERR_MSG_LEN"\n");
- return 1;
- }
- }
- d = atoi(buffer);
-
- if (d < 90)
- e = AGUDO;
- else if (d == 90)
- e = RECTO;
- else if (d > 90)
- e = OBTUSO;
-
-
- switch (e)
- {
- case AGUDO:
- printf("El angulo es AGUDO\n");
- break;
- case RECTO:
- printf("El angulo es RECTO\n");
- break;
- case OBTUSO:
- printf("El angulo es OBTUSO\n");
- break;
- }
- return 0;
-}
-
-
-
-
diff --git a/95.11/guia02/ex08.c b/95.11/guia02/ex08.c
@@ -1,73 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-#define MAX_LEN 5 // max digits of the entered degree;
-#define ERR_MSG_LEN "El angulo ingresado contiene demasiados digitos"
-
-#define FST_YR 48
-#define SND_YR 95
-#define TRD_YR 143
-
-
-typedef enum {
- FIRST, SECOND, THIRD, FOURTH
-} year_t;
-
-
-void clean(char *buffer)
-{
- for(size_t i = 0; i < MAX_LEN; i++)
- buffer[i] = '\0';
-}
-
-
-int main(void) {
-
- char buffer[MAX_LEN];
- clean(buffer);
- int c, d, i;
- year_t e;
- i = 0;
- while(((c = getchar()) != EOF) && c != '\n') {
- if(i < MAX_LEN) {
- buffer[i] = c;
- i++;
- } else if (i >= MAX_LEN) {
- fprintf(stderr, ERR_MSG_LEN"\n");
- return 1;
- }
- }
- d = atoi(buffer);
-
- if (d <= FST_YR)
- e = FIRST;
- else if ((d > FST_YR) && (d <= SND_YR))
- e = SECOND;
- else if ((d > SND_YR) && d <= (TRD_YR))
- e = THIRD;
- else if (d > TRD_YR)
- e = FOURTH;
-
-
- switch (e)
- {
- case FIRST:
- printf("Primer año\n");
- break;
- case SECOND:
- printf("Segundo año\n");
- break;
- case THIRD:
- printf("Tercer año\n");
- break;
- case FOURTH:
- printf("Curto año o superior\n");
- break;
- }
- return 0;
-}
-
-
-
-
diff --git a/95.11/guia02/ex09.c b/95.11/guia02/ex09.c
@@ -1,107 +0,0 @@
-/* Reads a number of credits from stdin and prints the corresponding
- grade of the Engineer in stdout*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-#define MAX_LEN 5 // max digits of the entered degree;
-#define ERR_MSG_LEN "El numero ingresado contiene demasiados digitos"
-#define ERR_NEG_MSG "El numero ingresado no es valido"
-
-#define FST_YR 52
-#define SND_YR 104
-#define TRD_YR 156
-
-#define FST_MSG "Primer año"
-#define SND_MSG "Segundo año"
-#define TRD_MSG "Tercer año"
-#define FTH_MSG "Cuarto año"
-
-typedef enum {
- FIRST, SECOND, THIRD, FOURTH
-} year_t;
-
-typedef enum {
- OK, ERROR
-} status_t;
-
-status_t clean(char *buffer)
-{
- if(buffer == NULL)
- return ERROR;
-
- for(size_t i = 0; i < MAX_LEN; i++)
- buffer[i] = '\0';
-
- return OK;
-}
-
-
-int main(void) {
-
- /* Defining variables */
- char buffer[MAX_LEN];
- int c, credits, i;
- year_t year;
- i = 0;
-
- /* Cleaning buffer in case it contains a random number */
- if(clean(buffer) == ERROR)
- return ERROR;
-
- /* Reading one char from stdin and storing it on a buffer until EOF */
- while(((c = getchar()) != EOF) && c != '\n') {
- if(i < MAX_LEN) {
- buffer[i] = c;
- i++;
- } else if (i >= MAX_LEN) {
- fprintf(stderr, ERR_MSG_LEN"\n");
- return 1;
- }
- }
-
- /* Converting the first portion of buffer to int with atoi()
- and cleaning the buffer */
- credits = atoi(buffer);
- if(clean(buffer) == ERROR)
- return ERROR;
-
- /* Checks if credits is a valid number */
- if(credits < 0) {
- fprintf(stderr, ERR_NEG_MSG"\n");
- return 1;
- }
-
- /* Evaluating the numbers of credits to match the current year */
- if (credits <= FST_YR)
- year = FIRST;
- else if ((credits > FST_YR) && (credits <= SND_YR))
- year = SECOND;
- else if ((credits > SND_YR) && (credits <= TRD_YR))
- year = THIRD;
- else if (credits > TRD_YR)
- year = FOURTH;
-
- /* Printing to stdout the corresponding year */
- switch (year)
- {
- case FIRST:
- printf(FST_MSG"\n");
- break;
- case SECOND:
- printf(SND_MSG"\n");
- break;
- case THIRD:
- printf(TRD_MSG"\n");
- break;
- case FOURTH:
- printf(FTH_MSG"\n");
- break;
- }
- return OK;
-}
-
-
-
-
diff --git a/95.11/guia02/ex10.c b/95.11/guia02/ex10.c
@@ -1,39 +0,0 @@
-#include <stdio.h>
-
-
-#define TM "3M Corporation"
-#define MAXWELL "Maxwell Corporation"
-#define SONY "Sony Corporation"
-#define VERBATIM "Verbatim Corporation"
-
-typedef enum {
- TM_CORPORATION,
- MAXWELL_CORPORATION,
- SONY_CORPORATION,
- VERBATIM_CORPORATION
-} manufacturer_t;
-
-
-int main(void) {
- manufacturer_t c;
- printf("Introduzca un Id. de fabricante: ");
- c = (getchar() - '0');
- switch(c) {
- case TM_CORPORATION:
- printf(TM"\n");
- break;
- case MAXWELL_CORPORATION:
- printf(MAXWELL"\n");
- break;
- case SONY_CORPORATION:
- printf(SONY"\n");
- break;
- case VERBATIM_CORPORATION:
- printf(VERBATIM"\n");
- break;
- default:
- printf("El numero ingresado no es valido\n");
- return 1;
- }
- return 0;
-}
diff --git a/95.11/guia02/ex11.c b/95.11/guia02/ex11.c
@@ -1,39 +0,0 @@
-#include <stdio.h>
-
-
-#define TM "3M Corporation"
-#define MAXWELL "Maxwell Corporation"
-#define SONY "Sony Corporation"
-#define VERBATIM "Verbatim Corporation"
-
-typedef enum {
- TM_CORPORATION = '3',
- MAXWELL_CORPORATION = 'M',
- SONY_CORPORATION = 'S',
- VERBATIM_CORPORATION = 'V'
-} manufacturer_t;
-
-
-int main(void) {
- manufacturer_t c;
- printf("Introduzca un Id. de fabricante: ");
- c = getchar();
- switch(c) {
- case TM_CORPORATION:
- printf(TM"\n");
- break;
- case MAXWELL_CORPORATION:
- printf(MAXWELL"\n");
- break;
- case SONY_CORPORATION:
- printf(SONY"\n");
- break;
- case VERBATIM_CORPORATION:
- printf(VERBATIM"\n");
- break;
- default:
- printf("El numero ingresado no es valido\n");
- return 1;
- }
- return 0;
-}
diff --git a/95.11/guia02/ex14.c b/95.11/guia02/ex14.c
@@ -1,11 +0,0 @@
-#include <stdio.h>
-
-typedef enum {
- 1200, 2400, 4800, 9600
-} baudrate_t;
-
-int main(void)
-{
- baudrate_t baudrate = 9600;
- return 0;
-}
diff --git a/95.11/guia02/ex16.c b/95.11/guia02/ex16.c
@@ -1,16 +0,0 @@
-#include <stdio.h>
-
-#define TRUE 0
-
-#ifdef TRUE
- #undef TRUE
- #define TRUE 1
-#endif
-
-int main(void)
-{
- printf("TRUE = %d\n", TRUE);
- return 0;
-}
-
-
diff --git a/95.11/guia02/ex17.c b/95.11/guia02/ex17.c
@@ -1,12 +0,0 @@
-#include <stdio.h>
-
-int main(void)
-{
- #ifdef DEBUG
- printf("DEBUGGING\n");
- #endif
-
- printf("Hello world!\n");
-
- return 0;
-}
diff --git a/95.11/guia02/ex18.c b/95.11/guia02/ex18.c
@@ -1,92 +0,0 @@
-#include <stdio.h>
-
-#define LANGUAGE GER // Define language in which month are displyed ESP,GER,ENG
-
-#if LANGUAGE == ESP
- #define JANUARY "ENERO"
- #define FEBRUARY "FEBRERO"
- #define MARCH "MARZO"
- #define APRIL "ABRIL"
- #define MAYO "MAYO"
- #define JUNE "JUNIO"
- #define JULY "JULIO"
- #define AUGUST "AGOSTO"
- #define SEPTEMBER "SEPTIEMBRE"
- #define OCTOBER "OCTUBRE"
- #define NOVEMBER "NOVIEMBRE"
- #define DECEMBER "DICIEMBRE"
-#elif LANGUAGE == GER
- #define JANUARY "JANUAR"
- #define FEBRUARY "FEBRUAR"
- #define MARCH "MÄRZ"
- #define APRIL "APRIL"
- #define MAYO "MAI"
- #define JUNE "JUNI"
- #define JULY "JULI"
- #define AUGUST "AUGUST"
- #define SEPTEMBER "SEPTEMBER"
- #define OCTOBER "OKTOBER"
- #define NOVEMBER "NOVEMBER"
- #define DECEMBER "DEZEMBER"
-#else
- #define JANUARY "JANUARY"
- #define FEBRUARY "FEBRUARY"
- #define MARCH "MARCH"
- #define APRIL "ABPRIL"
- #define MAYO "MAY"
- #define JUNE "JUNE"
- #define JULY "JULY"
- #define AUGUST "AUGUST"
- #define SEPTEMBER "SEPTEMBER"
- #define OCTOBER "OCTOBER"
- #define NOVEMBER "NOVEMBER"
- #define DECEMBER "DECEMBER"
-#endif
-
-typedef enum {
- JAN, FEB, MAR, APR, MAY, JUN, JUL, AGO, SEP, OCT, NOV, DEC
-} mes_t;
-
-int main(void) {
- mes_t mes = MAR;
- switch(mes)
- {
- case JAN:
- printf(JANUARY"\n");
- break;
- case FEB:
- printf(FEBRUARY"\n");
- break;
- case MAR:
- printf(MARCH"\n");
- break;
- case APR:
- printf(APRIL"\n");
- break;
- case MAY:
- printf(MAYO"\n");
- break;
- case JUN:
- printf(JUNE"\n");
- break;
- case JUL:
- printf(JULY"\n");
- break;
- case AGO:
- printf(AUGUST"\n");
- break;
- case SEP:
- printf(SEPTEMBER"\n");
- break;
- case OCT:
- printf(OCTOBER"\n");
- break;
- case NOV:
- printf(NOVEMBER"\n");
- break;
- case DEC:
- printf(DECEMBER"\n");
- break;
- }
- return 0;
-}
diff --git a/95.11/guia03/ex01.c b/95.11/guia03/ex01.c
@@ -1,20 +0,0 @@
-#include <stdio.h>
-
-#define MAX_LEN 100
-
-
-int main(void) {
-
- char s[MAX_LEN];
-
- printf("> ");
- scanf("%s", s);
- puts(s);
-
- printf("> ");
- // gets(s); removed from std C11 because it's very unsecure
- fgets(s, MAX_LEN, stdin);
- puts(s);
-
- return 0;
-}
diff --git a/95.11/guia03/ex02.c b/95.11/guia03/ex02.c
@@ -1,19 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-#define MAX_LEN 100
-#define ERR_EMPTY_MSG "no chars have been readed"
-
-int main(void) {
-
- char s[MAX_LEN];
- if(fgets(s, MAX_LEN, stdin) == NULL) {
- fprintf(stderr, ERR_EMPTY_MSG"\n");
- return 1;
- } else if(strcmp(s, "") == 0) {
- fprintf(stderr, ERR_EMPTY_MSG"\n");
- return 1;
- }
- printf("%s", s);
- return 0;
-}
diff --git a/95.11/guia03/ex04.c b/95.11/guia03/ex04.c
@@ -1,17 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-int main(void) {
-
- char s[] = "Hello world!\n";
- char aux;
- int n;
-
- for(n = strlen(s); n >= 0; n--) {
- aux = s[n];
- if(aux != '\n')
- putchar(aux);
- }
- putchar('\n');
- return 0;
-}
diff --git a/95.11/guia03/ex05.c b/95.11/guia03/ex05.c
@@ -1,14 +0,0 @@
-/* Calculates the length of a string and prints it on stdout */
-
-#include <stdio.h>
-
-int main(void) {
-
- char s[] = "Hello world!\n";
- int i;
- for(i = 0; s[i] != '\0'; i++) {
- }
- printf("%d\n", i);
-
- return 0;
-}
diff --git a/95.11/guia03/ex06.c b/95.11/guia03/ex06.c
@@ -1,24 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-
-
-int main(void) {
-
- char origen[] = "Hello world!\n";
- size_t i, len;
- len = strlen(origen);
- char destino[len];
-
- for(i = 0; i <= len; i++) {
- destino[i] = origen[i];
- if(i == len)
- destino[i + 1] = '\0';
- }
-
- printf("%s", origen);
- printf("%s", destino);
-
-
- return 0;
-}
diff --git a/95.11/guia03/ex07.c b/95.11/guia03/ex07.c
@@ -1,29 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-
-int main(void) {
-
- char s1[] = "Hello world!";
- char s2[] = "Hola mundo!";
-
-
- int i, s1_len, s2_len, cat_len;
- s1_len = strlen(s1);
- s2_len = strlen(s2);
-
- cat_len = ((s1_len + s2_len) + 1); // One more for the '\0' byte;
- char cat[cat_len];
-
- for(i = 0; i <= cat_len; i++) {
- if (i < s1_len) {
- cat[i] = s1[i];
- } else if (i >= s1_len) {
- cat[i] = s2[i - s1_len];
- } else if (i == cat_len) {
- cat[i + 1] = '\0';
- }
- }
- printf("%s\n", cat);
- return 0;
-}
diff --git a/95.11/guia03/ex08.c b/95.11/guia03/ex08.c
@@ -1,38 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-size_t str_len(const char *str) {
- if(str == NULL)
- return 1;
-
- size_t i;
- for(i = 0; str[i] != '\0'; i++)
- ;
-
- return i;
-}
-
-int main(void) {
-
- char s1[] = "ABC";
- char s2[] = "ABC";
-
- size_t s1_len, s2_len;
- int i, j, cmp;
-
- s1_len = str_len(s1);
- s2_len = str_len(s2);
-
- j = (s1_len > s2_len) ? s1_len : s2_len;
-
- for(i = 0, cmp = 0; i < j; i++) {
- if(s1[i] < s2[i]) {
- cmp -= (s2[i] - s1[i]);
- } else
- if (s1[i] > s2[i]) {
- cmp += (s1[i] - s2[i]);
- }
- }
- printf("%d\n", cmp);
- return 0;
-}
diff --git a/95.11/guia03/ex08_modular.c b/95.11/guia03/ex08_modular.c
@@ -1,66 +0,0 @@
-/* Makes a lexicographical comparison between two strings */
-/* similar to strcmp() function from <string.h> */
-
-#include <stdio.h>
-
-/* This function calculates the length of given string
- and returns the lenghth by its name as a size_t */
-size_t str_len(const char *str)
-{
- if(str == NULL)
- return 1;
- size_t i;
- for(i = 0; str[i] != '\0'; i++)
- ;
-
- return i;
-}
-
-/* This function is equivalent to strcmp() function from
- <string.h> library */
-int str_cmp(const char *str1, const char *str2)
-{
-// In case one of the given strings is NULL returns 1;
- if(str1 == NULL || str2 == NULL)
- return 1;
-
-
- char aux1, aux2;
- int i, j, cmp, str1_len, str2_len;
- str1_len = str_len(str1);
- str2_len = str_len(str2);
-
-// Assigns the length of the longer string to j;
- j = (str1_len > str2_len) ? str1_len : str2_len;
-
-// The for loop itinirate until the longest str ENDs
- for(i = 0, cmp = 0; i < j; i++) {
-
- aux1 = str1[i];
- aux2 = str2[i];
-
-// This statement assigns to cmp the difference between
-// the two coresponding chars of str1 and str2
- if(aux1 < aux2) {
- cmp -= (aux2 - aux1);
- } else if (aux1 > aux2) {
- cmp += (aux1 - aux2);
- }
-
- }
- return cmp;
-}
-
-
-int main(void) {
-
- char s1[] = "AB";
- char s2[] = "ABC";
-
- int i, j;
- i = str_cmp(s1, s2);
-
- printf("%d\n", i);
-
- return 0;
-}
diff --git a/95.11/guia03/ex09_modular.c b/95.11/guia03/ex09_modular.c
@@ -1,60 +0,0 @@
-/* Makes a lexicographical comparison between the first n */
-/* numbers of two given strings */
-/* similar to strncmp() function from <string.h> */
-
-#include <stdio.h>
-
-/* This function calculates the length of given string
- and returns it by its name, equivalent to strlen()
- function from <string.h> library */
-size_t str_len(const char *str)
-{
- if(str == NULL)
- return 1;
-
- size_t i;
- for(i = 0; str[i] != '\0'; i++)
- ;
-
- return i;
-}
-
-/* This function is equivalent to strncmp() function from
- <string.h> library */
-int str_cmp(const char *str1, const char *str2, size_t n)
-{
- if(str1 == NULL || str2 == NULL)
- return 1;
-
- char aux1, aux2;
- int i, j, cmp, str1_len, str2_len;
- str1_len = str_len(str1);
- str2_len = str_len(str2);
-
- if(n > str1_len || n > str2_len)
- return 1;
-
- for(i = 0, cmp = 0; i <= n; i++) {
- aux1 = str1[i];
- aux2 = str2[i];
- if(aux1 < aux2) {
- cmp -= (aux2 - aux1);
- } else if (aux1 > aux2) {
- cmp += (aux1 - aux2);
- }
- }
- return cmp;
-}
-
-
-int main(void) {
-
- char s1[] = "AB ";
- char s2[] = "ABC";
-
- int i;
- i = str_cmp(s1, s2, 4);
-
- printf("%d\n", i);
- return 0;
-}
diff --git a/95.11/guia03/ex10.c b/95.11/guia03/ex10.c
@@ -1,23 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-
-
-int main(void) {
-
- char src[] = "Hello world!\n";
- size_t i, n;
-
- n = 12;
- char cpy[n];
-
- for(i = 0; i <= n; i++) {
- cpy[i] = src[i];
- }
-
- printf("%s", src);
- printf("%s", cpy);
-
-
- return 0;
-}
diff --git a/95.11/guia03/ex11.c b/95.11/guia03/ex11.c
@@ -1,19 +0,0 @@
-#include <stdio.h>
-#include <ctype.h>
-
-int main(void)
-{
- char str[] = "hello world";
- int i;
- char aux;
-
- for(i = 0; (aux = str[i]) != '\0'; i++)
- if(islower(aux))
- str[i] = toupper(aux);
-
- printf("%s\n", str);
- return 0;
-}
-
-
-
diff --git a/95.11/guia03/ex12.c b/95.11/guia03/ex12.c
@@ -1,19 +0,0 @@
-#include <stdio.h>
-#include <ctype.h>
-
-int main(void)
-{
- char str[] = "HELLO WORLD";
- int i;
- char aux;
-
- for(i = 0; (aux = str[i]) != '\0'; i++)
- if(isupper(aux))
- str[i] = tolower(aux);
-
- printf("%s\n", str);
- return 0;
-}
-
-
-
diff --git a/95.11/guia03/ex13.c b/95.11/guia03/ex13.c
@@ -1,61 +0,0 @@
-// Reads a string from stdin and converts it to uppercase or lowercase
-// depending on an option readed from stdin
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-
-#define MSG_STR_PROMPT "Introduzca una cadena:"
-#define MSG_FMT_PROMPT "Convertir a: (0 - MAYUSCULAS / 1 - MINUSCULAS)"
-#define MSG_FMT_ERR "Err: Formato incorrecto"
-
-#define MAX_STR_LEN 100
-
-typedef enum {
- FMT_MAYUSCULAS, FMT_MINUSCULAS
-} format_t;
-
-
-int main ( void ) {
-
-
- char buffer[MAX_STR_LEN];
- char str[MAX_STR_LEN];
- format_t format;
-
-
- printf(MSG_STR_PROMPT"\n>> ");
- fgets(buffer, MAX_STR_LEN, stdin);
- strcpy(str, buffer);
-
- printf(MSG_FMT_PROMPT"\n>> ");
- format = (getchar () - '0');
- if((format < 0) || (format > 1)) {
- fprintf(stderr, MSG_FMT_ERR"\n");
- return 1;
- }
-
- printf("La cadena ingresada: %sOpcion elegida: %d\n", str, format);
-
- int i, aux;
- switch(format)
- {
- case FMT_MAYUSCULAS:
- for(i = 0; (aux = str[i]) != '\n'; i++) {
- if(islower(aux))
- str[i] = toupper(aux);
- }
- break;
- case FMT_MINUSCULAS:
- for(i = 0; (aux = str[i]) != '\n'; i++) {
- if(isupper(aux))
- str[i] = tolower(aux);
- }
- break;
- }
-
- printf("%s", str);
- return 0;
-}
diff --git a/95.11/guia03/ex14.c b/95.11/guia03/ex14.c
@@ -1,35 +0,0 @@
-#include <stdio.h>
-
-
-typedef enum {
- OK, ERROR
-} status_t;
-
-
-size_t rechar(char *str, char old, char new);
-
-
-int main( void ) {
-
- char str[] = "Hello world!";
-
- rechar(str, 'o', 'e');
-
- printf("%s\n", str);
- return OK;
-}
-
-
-
-size_t rechar(char *str, char old, char new) {
- if(str == NULL)
- return ERROR;
-
- int i;
- for(i = 0; str[i] != '\0'; i++) {
- if(str[i] == old) {
- str[i] = new;
- }
- }
- return OK;
-}
diff --git a/95.11/guia03/ex15.c b/95.11/guia03/ex15.c
@@ -1,21 +0,0 @@
-#include <stdio.h>
-
-#define MAX_LEN 100
-
-int main(void) {
-
- int i, j;
- char str[MAX_LEN];
-
- fgets(str, MAX_LEN, stdin);
-
- j = 0;
- while(str[j] == ' ')
- j++;
-
- for(i = 0; str[i] != '\0'; i++) {
- str[i] = str[i + j];
- }
- puts(str);
- return 0;
-}
diff --git a/95.11/guia03/ex16.c b/95.11/guia03/ex16.c
@@ -1,28 +0,0 @@
-// Reads a string from stdin and if it ends in blank
-// spaces it erase them and moves the '\n', '\0' chars
-// it performs a "right trim"
-
-
-#include <stdio.h>
-
-#define MAX_LEN 100
-
-
-int main ( void ) {
-
- int i, j, k;
- char str[MAX_LEN];
-
- if(fgets(str, MAX_LEN, stdin) == NULL)
- return 1;
-
- for(i = 0; str[i] != '\0'; i++)
- if(str[i + 1] == '\n')
- for(j = 0; str[i - j] == ' '; j++)
- ;
-
- str[(i - j) - 1] = str[i - 1];
- str[(i - j)] = '\0';
-
- return 0;
-}
diff --git a/95.11/guia03/ex17.c b/95.11/guia03/ex17.c
@@ -1,34 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-#define MAX_LEN 100
-
-
-int main ( void ) {
-
- int i, j;
-
- char s1[MAX_LEN];
- char s2[MAX_LEN];
-
- if(fgets(s1, MAX_LEN, stdin) == NULL)
- return 1;
-
- if(fgets(s2, MAX_LEN, stdin) == NULL)
- return 1;
-
- if(strlen(s2) > strlen(s1))
- return 1;
-
- for(i = 0; s1[i] != '\0'; i++)
- if(s1[i] == s2[0])
- for(j = 0; (s2[j] != '\0'); j++)
- if(s1[i] == s2[j]) {
- putchar(s1[i]);
- i++;
- }
- putchar('\n');
- return 0;
-}
-
-
diff --git a/95.11/guia03/ex18.c b/95.11/guia03/ex18.c
@@ -1,57 +0,0 @@
-// Reads a string of chars from stdin and check if it's
-// a palindrome.
-
-#include <stdio.h>
-#include <ctype.h>
-
-#define MAX_LEN 100
-
-
-int main ( void ) {
-
- char str[MAX_LEN];
- int aux, len, i, j;
-
- if(fgets(str, MAX_LEN, stdin) == NULL)
- return 1;
-
-// Converts all the string to lowercase;
- for(i = 0; str[i] != '\0'; i++)
- if(isupper(str[i]))
- str[i] = tolower(str[i]);
-
-// If the readed string it's a sentence, erases all
-// the blank spaces between the words;
- for(i = 0; str[i] != '\0'; i++) {
- if(str[i] == ' ') {
- aux = i;
- while(str[aux] != '\0') {
- str[aux] = str[aux + 1];
- aux++;
- }
- }
- }
-
-// Counts the length of the string;
- for(i = 0; str[i] != '\n'; i++)
- ;
-
-// Stored the lengh of the string for later,
-// and subtract one from i because of the last char;
- len = i;
- i = (i - 1);
-
-// This part compares one by one the chars from the
-// string, first with last, second with before last,
-// and so on, only comparing the next one if the previous
-// one was equal;
- for(j = 0; (str[j] == str[i]) && (str[j] != '\0'); j++, i--)
- ;
-
-// If the string or sentence its palindrome, then in the previous
-// block j would end with the value of the lengh, stored previously;
- if(j == len)
- printf("La cadena es capicua.\n");
-
- return 0;
-}
diff --git a/95.11/guia03/ex20.c b/95.11/guia03/ex20.c
@@ -1,24 +0,0 @@
-// Reads a string of chars from stdin and converts
-// it to a number, int or float;
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_LEN 100
-
-int main ( void ) {
-
- char buffer[MAX_LEN];
- int num1;
- float num2;
-
- fgets(buffer, MAX_LEN, stdin);
- num1 = atoi(buffer);
- printf("n1(int) = %d\n", num1);
-
- fgets(buffer, MAX_LEN, stdin);
- num2 = atof(buffer);
- printf("n2(float) = %.2f\n", num2);
-
- return 0;
-}
diff --git a/95.11/guia03/ex21.c b/95.11/guia03/ex21.c
@@ -1,20 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_LEN 100
-
-int main ( void ) {
-
- char buffer[MAX_LEN];
- float num;
- char num2[MAX_LEN];
-
- if(fgets(buffer, MAX_LEN, stdin) == NULL)
- return 1;
-
- num = atof(buffer);
- sprintf(num2, "%.2f\n", num);
-
- printf("%s", num2);
- return 0;
-}
diff --git a/95.11/guia03/ex22.c b/95.11/guia03/ex22.c
@@ -1,20 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_LEN 100
-
-int main ( void ) {
-
- char buffer[MAX_LEN];
- int num;
- char num2[MAX_LEN];
-
- if(fgets(buffer, MAX_LEN, stdin) == NULL)
- return 1;
-
- num = atoi(buffer);
- sprintf(num2, "%d\n", num);
-
- printf("%s", num2);
- return 0;
-}
diff --git a/95.11/guia03/ex23.c b/95.11/guia03/ex23.c
@@ -1,23 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_LEN 100
-
-int main ( void ) {
-
- char buffer[MAX_LEN];
- int num;
- char num2[MAX_LEN];
-
- if(fgets(buffer, MAX_LEN, stdin) == NULL)
- return 1;
-
- num = atoi(buffer);
-
-// Converts num to octal and stores it on num2 str;
- sprintf(num2, "%o\n", num);
-
-// prints the string with the octal number;
- printf("%s", num2);
- return 0;
-}
diff --git a/95.11/guia03/ex23_imp.c b/95.11/guia03/ex23_imp.c
@@ -1,28 +0,0 @@
-// Reads an integer from stdin and prints it
-// on stdout in octal base;
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_LEN 100
-#define ERR_MSG_NEG "Err: the number is negative"
-
-int main ( void ) {
-
- int num;
- char buffer[MAX_LEN];
-
- if(fgets(buffer, MAX_LEN, stdin) == NULL)
- return 1;
-
-// Converts the input str to int, if the number
-// is negative, puts an error message on stderr;
- if((num = atoi(buffer)) < 0 ) {
- fprintf(stderr, ERR_MSG_NEG"\n");
- return 1;
- }
-
-// prints the integer in octal base;
- printf("%o\n", num);
- return 0;
-}
diff --git a/95.11/guia03/ex24.c b/95.11/guia03/ex24.c
@@ -1,27 +0,0 @@
-// Reads a number from stdin and prints it
-// in hexadecimal base on stout;
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_LEN 100
-
-int main ( void ) {
-
- char buffer[MAX_LEN];
- int num;
- char num2[MAX_LEN];
-
- if(fgets(buffer, MAX_LEN, stdin) == NULL)
- return 1;
-
- num = atoi(buffer);
-
-// Converts num to hexadecimal and stores it
-// on num2 str;
- sprintf(num2, "%x\n", num);
-
-// prints the string with the octal number;
- printf("%s", num2);
- return 0;
-}
diff --git a/95.11/guia03/ex24_imp.c b/95.11/guia03/ex24_imp.c
@@ -1,28 +0,0 @@
-// Reads an non-negative integer from stdin and prints it
-// on stdout in hexadecimal base;
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_LEN 100
-#define ERR_MSG_NEG "Err: the number is negative"
-
-int main ( void ) {
-
- unsigned int num;
- char buffer[MAX_LEN];
-
- if(fgets(buffer, MAX_LEN, stdin) == NULL)
- return 1;
-
-// Converts the input str to int, if the number
-// is negative, puts an error message on stderr;
- if((num = atoi(buffer)) < 0 ) {
- fprintf(stderr, ERR_MSG_NEG"\n");
- return 1;
- }
-
-// prints the integer in hexadecimal base;
- printf("%X\n", num);
- return 0;
-}
diff --git a/95.11/guia03/ex25_imp.c b/95.11/guia03/ex25_imp.c
@@ -1,53 +0,0 @@
-// Reads an integer from stdin and prints it
-// on stdout in binary base.
-// only for numbers below 128;
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_LEN 8
-#define ERR_MSG_NEG "Err: invalid number!"
-
-int main ( void ) {
-
- int i, num;
- char buffer[MAX_LEN];
-// 0000 0000
- int bin[MAX_LEN] = {0,0,0,0,0,0,0,0};
-
- if(fgets(buffer, MAX_LEN, stdin) == NULL)
- return 1;
-
-// Converts the input str to int, if the number
-// is negative or greater than 128, puts an
-// error message on stderr;
- if((num = atoi(buffer)) < 0 || num > 128) {
- fprintf(stderr, ERR_MSG_NEG"\n");
- return 1;
- }
-
-// Converts num to binary base by dividing it
-// by 2 until its zero, the rest of the division
-// is stored in every itineration in bin[];
- for(i = 0; num != 0; i++) {
- if((num % 2) == 1) {
- bin[i] = 1;
- } else {
- bin[i] = 0;
- }
- num = (num / 2);
- }
-
-// This part print bin in reverse order because
-// the previous algorithm stores the values in
-// reverse order;
- for(i = 7; i >= 0; i--) {
- if(i == 3)
- putchar(' ');
-
- printf("%d", bin[i]);
- }
-
- putchar('\n');
- return 0;
-}
diff --git a/95.11/guia03/ex26.c b/95.11/guia03/ex26.c
@@ -1,58 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_LEN 100
-#define ERR_MAX_STR_LEN "Err: the entered number is too big"
-
-
-int main ( void ) {
-
- char buffer[MAX_LEN], str1[MAX_LEN], str2[MAX_LEN];
- char dest[MAX_LEN];
- int i, j, num;
-
- if(fgets(str1, MAX_LEN, stdin) == NULL) {
- return 1;
- }
-
-// This part counts the length of the first string
-// and replaces the new line character for a blank space;
- for(i = 0; str1[i] != '\0'; i++)
- if(str1[i] == '\n')
- str1[i] = ' ';
- str1[i + 1] = '\0';
-
- if(fgets(str2, MAX_LEN, stdin) == NULL) {
- return 1;
- }
-
- if(fgets(buffer, MAX_LEN, stdin) == NULL) {
- return 1;
- }
-
- num = atoi(buffer);
-
-// This part checks if the input number is bigger than
-// the length of the first string;
- if(num > i) {
- fprintf(stderr, ERR_MAX_STR_LEN"\n");
- return 1;
- }
-
-
-// Removes the new line chracter from string two;
- for(i = 0; str2[i] != '\0'; i++)
- if(str2[i] == '\n')
- str2[i] = '\0';
-
- for(i = 0, j = 0; str2[j] != '\0'; i++) {
- if((i <= num) && (str1[i] != '\0')) {
- dest[i] = str1[i];
- } else {
- dest[i] = str2[j];
- j++;
- }
- }
- printf("%s\n", dest);
- return 0;
-}
diff --git a/95.11/guia03/ex27.c b/95.11/guia03/ex27.c
@@ -1,27 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_LEN 100
-
-int main ( void ) {
-
- char str[MAX_LEN], buffer[MAX_LEN];
- int i, j, num;
-
- if(fgets(str, MAX_LEN, stdin) == NULL)
- return 1;
-
- if(fgets(buffer, MAX_LEN, stdin) == NULL)
- return 1;
-
- num = atoi(buffer);
-
- for(i = 0; str[i] != '\0'; i++)
- if(str[i] == '\n')
- i++;
- for(j = 0; j <= num; j++)
- str[i + j] = ' ';
-
- printf("%s\n", str);
- return 0;
-}
diff --git a/95.11/guia03/ex28.c b/95.11/guia03/ex28.c
@@ -1,13 +0,0 @@
-#include <stdio.h>
-
-#define MAX_LEN 20
-
-int main (void) {
-
- int i, vector[MAX_LEN];
-
- for(i = 0; i < MAX_LEN; i++)
- printf("%d\n", vector[i]);
-
- return 0;
-}
diff --git a/95.11/guia03/ex29.c b/95.11/guia03/ex29.c
@@ -1,23 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_LEN 20
-
-int main (void) {
-
- int i, suma, vector[MAX_LEN], vector_end;
- char buffer[MAX_LEN];
-
- vector_end = MAX_LEN;
- for(i = 0, suma = 0; i < vector_end; i++) {
- if(fgets(buffer, sizeof(int) + 1, stdin) != NULL) {
- vector[i] = atoi(buffer);
- suma += vector[i];
- } else {
- vector_end = i;
- i = MAX_LEN;
- }
- }
- printf("%d\n", suma);
- return 0;
-}
diff --git a/95.11/guia03/ex30.c b/95.11/guia03/ex30.c
@@ -1,34 +0,0 @@
-// Calculates the arithmetic mean of a certain amount of
-// numbers. First ask for the quantity and then calculates
-// it and prints it;
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MAX_LEN 20
-
-int main (void) {
-
- int i, n;
- float x, suma, numbers[MAX_LEN];
- char buffer[MAX_LEN];
-
-// Read the quantity of numbers to mean;
- if(fgets(buffer, sizeof(int) + 1, stdin) != NULL)
- n = atoi(buffer);
- else return 1;
-
-// Read the values to mean and stores it on numbers;
- for(i = 0, suma = 0; i < n; i++) {
- if(fgets(buffer, sizeof(int) + 1, stdin) != NULL) {
- numbers[i] = atof(buffer);
- suma += numbers[i];
- } else return 1;
- }
-// Calculate the arithmetic mean and stores it on x;
- x = ((1 / (float)n) * suma);
-
-// Print the arithmetic mean;
- printf("x = %.3f\n", x);
- return 0;
-}
diff --git a/95.11/guia03/ex30_std_dev.c b/95.11/guia03/ex30_std_dev.c
@@ -1,45 +0,0 @@
-// Calculates the arithmetic mean of a certain amount of
-// numbers. First ask for the quantity and then calculates
-// it and prints it;
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-
-#define MAX_LEN 20
-
-int main (void) {
-
- int i, n;
- float d, x, suma, numbers[MAX_LEN];
- char buffer[MAX_LEN];
-
-// Read the quantity of numbers to mean;
- if(fgets(buffer, sizeof(int) + 1, stdin) != NULL)
- n = atoi(buffer);
- else return 1;
-
-// Read the values to mean and stores it on numbers;
- for(i = 0, suma = 0; i < n; i++) {
- if(fgets(buffer, sizeof(int) + 1, stdin) != NULL) {
- numbers[i] = atof(buffer);
- suma += numbers[i];
- } else return 1;
- }
-
-// Calculate the arithmetic mean and stores it on x;
- x = ((1 / (float)n) * suma);
-
-// Calculates the standard deviation;
- for(i = 0; i < n; i++) {
- suma += (numbers[i] - x);
- d = sqrtf((1/n) * powf(suma, 2.0));
- }
-
-// Print the arithmetic mean;
- printf("x = %.3f\n", x);
-
-// Print the standard deviation;
- printf("d = %.3f\n", d);
- return 0;
-}
diff --git a/95.11/guia03/ex32.c b/95.11/guia03/ex32.c
@@ -1,65 +0,0 @@
-// Calculates the max or min in an array of numbers;
-// of type int;
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-
-#define MAX_ELEM 10
-#define NO_ARGUMENT_ENTERED 1
-#define EXTREMO_ARGUMENT 1
-
-typedef enum {
- MAXIMUM,
- MINIMUM
-} extreme_t;
-
-typedef enum {
- OK,
- ERROR_INVOCATING_PROGRAM,
- ERROR_NULL_POINTER
-} status_t;
-
-status_t validate_arguments (int argc, char ** argv);
-
-int main (int argc, char * argv[])
-{
- size_t i;
- int vector[MAX_ELEM] = {9, 10, 25, 31, 9, 5, 11, 46, 50, 20};
- extreme_t extremo;
- status_t st;
-
- if((st = validate_arguments(argc, argv)) != OK)
- return st;
-
- extremo = atoi(argv[EXTREMO_ARGUMENT]);
- if(extremo == MAXIMUM) {
- // Find maximum element in array;
- int maximum;
- for(i = 0, maximum = INT_MIN; i < (sizeof(vector)/sizeof(vector[0])); i++)
- if(vector[i] > maximum)
- maximum = vector[i];
-
- printf("%d\n", maximum);
- } else if (extremo == MINIMUM){
- // Find minimum element in array;
- int minimum;
- for(i = 0, minimum = INT_MAX; i < (sizeof(vector)/sizeof(vector[0])); i++)
- if(vector[i] < minimum)
- minimum = vector[i];
-
- printf("%d\n", minimum);
- }
- return 0;
-}
-
-status_t validate_arguments (int argc, char ** argv) {
- if(argc == NO_ARGUMENT_ENTERED)
- return ERROR_INVOCATING_PROGRAM;
-
- else if (argv == NULL)
- return ERROR_NULL_POINTER;
-
- else return OK;
-}
-
diff --git a/95.11/guia04/ex02.c b/95.11/guia04/ex02.c
@@ -1,15 +0,0 @@
-#include <stdio.h>
-
-#define MAX 10
-
-int main ( void ) {
-
- int x, array[MAX];
- array[4] = 1;
-
- x = array[4];
-
- printf("%d\n", x);
-
- return 0;
-}
diff --git a/95.11/guia05/ex01.c b/95.11/guia05/ex01.c
@@ -1,18 +0,0 @@
-#include <stdio.h>
-
-unsigned long fact ( int num ) {
- unsigned long j, res;
- res = 1;
-
- for (j = 1; j <= num; j++) {
- res = (res * j);
- }
- return res;
-}
-
-int main ( void ) {
-
- printf("%lu\n", fact(5));
-
- return 0;
-}
diff --git a/95.11/guia05/ex02.c b/95.11/guia05/ex02.c
diff --git a/95.11/guia06/ex01.c b/95.11/guia06/ex01.c
@@ -1,20 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#define ERR_ARG "Error: No arguments"
-
-int main (int argc, char *argv[]) {
- size_t i;
- if(argc == 1) {
- fprintf(stderr, ERR_ARG"\n");
- return 1;
- }
-
- printf("argc: %d \n", argc);
-
- for (i = 0; i < argc; i++) {
- printf("argv[%ld] = %s \n", i, argv[i]);
- }
-
- return EXIT_SUCCESS;
-}
diff --git a/95.11/guia07/ex05.c b/95.11/guia07/ex05.c
@@ -1,31 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-#define MASK_BYTE 0xFF
-
-int main(void) {
-
-// 0x10 30 25 F4
- unsigned int n = 271590900;
-
-// Arreglo de 4 bytes;
- unsigned char v[4];
-
- size_t i;
-/*
- v[0] = (n >> 24) & 0xFF;
- v[1] = (n >> 16) & 0xFF;
- v[2] = (n >> 8) & 0xFF;
- v[3] = (n >> 0) & 0xFF;
-*/
- for(i = 0; i < sizeof(unsigned int); i++)
- v[i] = (n >> ( (sizeof(unsigned int) - 1 - i) * 8 )) & 0xFF;
-
- printf("%d\n", n);
- printf("%x\n", n);
-
- for(i = 0; i < sizeof(unsigned int); i++)
- printf("v[%lu] = %x\n", i, v[i]);
-
- return EXIT_SUCCESS;
-}
diff --git a/95.11/guia08/ex01.c b/95.11/guia08/ex01.c
@@ -1,58 +0,0 @@
-// Clones a given string entered as arguments of function main;
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define NO_ARGUMENT 1
-#define INIT_SIZE 100
-
-typedef enum {
- OK,
- ERROR_PROGRAM_INVOCATION,
- ERROR_NULL_POINTER,
- ERROR_ALLOC_MEMORY
-} status_t;
-
-status_t validar_argumentos(int argc, char **argv);
-
-int main (int argc, char * argv[])
-{
- char *dest;
- size_t i;
- status_t st;
-
-// Verify if arguments are right;
- if((st = validar_argumentos(argc, argv) != OK))
- return st;
-
-// Allocates memmory in heap of size INIT_SIZE;
- if((dest = (char *)malloc(INIT_SIZE * sizeof(char))) == NULL)
- return ERROR_ALLOC_MEMORY;
-
-// Assigns 1 to i to avoid the first element of argv,
-// which is the program name. Then copies every string of argv
-// into dest and prints it on stdout;
- for(i = 1; (int)i < argc; i++) {
- strcpy(dest, argv[i]);
- // Puts a space in between strings, avoiding a blank
- // space after first string is printed;
- if(i != 1) putchar(' ');
- printf("%s", dest);
- }
-
-// Adds the new line character;
- putchar('\n');
- free(dest);
- return OK;
-}
-
-status_t validar_argumentos(int argc, char **argv)
-{
- if(argc == NO_ARGUMENT)
- return ERROR_PROGRAM_INVOCATION;
-
- else if(argv == NULL)
- return ERROR_NULL_POINTER;
-
- else return OK;
-}
diff --git a/95.11/guia08/malloc_basics.c b/95.11/guia08/malloc_basics.c
@@ -1,22 +0,0 @@
-// Stores an array of numbers in heap, then prints it on
-// stdout finally frees the memory used;
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#define ARR_LEN 10
-
-int main (void)
-{
- int *p;
-
- if((p = (int*)malloc(ARR_LEN * sizeof(int))) == NULL)
- return 1;
-
- for(int i = 0; i < ARR_LEN; i++) {
- *(p + i) = i;
- printf("%d\n", *(p + i));
- }
- free(p);
- return 0;
-}
diff --git a/95.11/guia08/text.txt b/95.11/guia08/text.txt
@@ -1,23 +0,0 @@
-The malloc() function allocates size bytes and returns a pointer
-to the allocated memory. The memory is not initialized. If size
-is 0, then malloc() returns either NULL, or a unique pointer value
-that can later be successfully passed to free().
-
-The free() function frees the memory space pointed to by ptr,
-which must have been returned by a previous call to malloc(), cal‐
-loc(), or realloc(). Otherwise, or if free(ptr) has already been
-called before, undefined behavior occurs. If ptr is NULL, no op‐
-eration is performed.
-
-The calloc() function allocates memory for an array of nmemb ele‐
-ments of size bytes each and returns a pointer to the allocated
-memory. The memory is set to zero. If nmemb or size is 0, then
-calloc() returns either NULL, or a unique pointer value that can
-later be successfully passed to free(). If the multiplication of
-nmemb and size would result in integer overflow, then calloc() re‐
-turns an error. By contrast, an integer overflow would not be de‐
-tected in the following call to malloc(), with the result that an
-incorrectly sized block of memory would be allocated:
-
- malloc(nmemb * size);
-
diff --git a/95.11/tp01/Makefile b/95.11/tp01/Makefile
@@ -1,18 +0,0 @@
-$(CC)=gcc
-
-all: make_main clean
-
-
-make_main: main.o arguments.o
- $(CC) main.o arguments.o -o main
-
-main.o: src/main.c include/main.h include/arguments.h include/macros.h
- $(CC) -c src/main.c
-
-arguments.o: src/arguments.c include/arguments.h include/macros.h
- $(CC) -c src/arguments.c
-
-clean:
- rm -f *.o
-
-
diff --git a/95.11/tp01/README.md b/95.11/tp01/README.md
@@ -1,17 +0,0 @@
-# TRABAJO PRACTICO NUMERO 1 - ALGORITMOS Y PROGRAMACION I (95.11)
-
-This folder contains the first project of "algoritmos y
-programacion I" a subject from Facultad de Ingenieria de la
-Universidad de Buenos Aires. This project is a program that
-runs on CLI which its function is to process data entered via
-a .csv file, with a specified format, otherwise it will be considered
-corrupt.
-
-What it does is receive a number for a country, date, and number of
-cases (of COVID19), and prints it on stdout with a human readable
-format.
-
-Bibliography:
-
-"The C programming language" - Brian W. Kernighan & Dennis Ritchie
-
diff --git a/95.11/tp01/include/arguments.h b/95.11/tp01/include/arguments.h
@@ -1,13 +0,0 @@
-#include "main.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#ifndef ARGUMENTS_H
-#define ARGUMENTS_H
-
-status_t validate_arguments(int argc, char * argv[]);
-
-status_t set_files_name(int argc, char * argv[], char * src, char * dest);
-
-#endif
diff --git a/95.11/tp01/include/data.h b/95.11/tp01/include/data.h
@@ -1,4 +0,0 @@
-#ifndef DATA_H
-#define DATA_H
-
-#endif
diff --git a/95.11/tp01/include/macros.h b/95.11/tp01/include/macros.h
@@ -1,10 +0,0 @@
-#ifndef MACROS_H
-#define MACROS_H
-
-#define NO_CMD_ARGUMENTS 1
-#define MAX_CMD_ARGUMENTS 5
-
-#define SOURCE_ARGUMENT "-in"
-#define DESTINATION_ARGUMENT "-out"
-
-#endif
diff --git a/95.11/tp01/include/main.h b/95.11/tp01/include/main.h
@@ -1,10 +0,0 @@
-#ifndef MAIN_H
-#define MAIN_H
-
-typedef enum {
- OK,
- ERROR_INVOCATING_PROGRAM,
- ERROR_NULL_POINTER
-} status_t;
-
-#endif
diff --git a/95.11/tp01/main b/95.11/tp01/main
Binary files differ.
diff --git a/95.11/tp01/src/arguments.c b/95.11/tp01/src/arguments.c
@@ -1,35 +0,0 @@
-#include "../include/arguments.h"
-#include "../include/macros.h"
-
-
-// Checks if the arguments are right;
-status_t validate_arguments(int argc, char * argv[])
-{
- if(argc == NO_CMD_ARGUMENTS)
- return ERROR_INVOCATING_PROGRAM;
- else if(argv == NULL)
- return ERROR_NULL_POINTER;
-
- return OK;
-}
-
-// Set the files name acording to the arguments;
-status_t set_files_name(int argc, char * argv[], char * src, char * dest)
-{
- int i;
- for(i = 1; i < argc; i++) {
- if(!strcmp(argv[i], SOURCE_ARGUMENT)) {
- printf("Encontre un '-in'\n");
- strcpy(src, argv[++i]);
- printf("\tthen input file: %s\n", src);
- }
- if(!strcmp(argv[i], DESTINATION_ARGUMENT)) {
- printf("Encontre un '-out'\n");
- strcpy(dest, argv[++i]);
- printf("\tthen output file: %s\n", argv[i]);
- }
-
- }
- return OK;
-}
-
diff --git a/95.11/tp01/src/data.c b/95.11/tp01/src/data.c
diff --git a/95.11/tp01/src/main.c b/95.11/tp01/src/main.c
@@ -1,28 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "../include/main.h"
-#include "../include/arguments.h"
-#include "../include/macros.h"
-
-int main(int argc, char * argv[])
-{
- status_t st;
- if((st = validate_arguments(argc, argv)) != OK)
- return st;
-
- char * src;
- char * dest;
-
- src = (char *)malloc(100 * sizeof(char));
- dest = (char *)malloc(100 * sizeof(char));
-
- if((st = set_files_name(argc, argv, src, dest)) != OK)
- return st;
-
- printf("src: %s, dest: %s;\n", src, dest);
-
- return OK;
-}
-
-