Parcourir la source

New chapter 3...

master
Ognjen Milan Robovic il y a 7 mois
Parent
révision
3f23d0f197
5 fichiers modifiés avec 93 ajouts et 2 suppressions
  1. +1
    -1
      chapters/chapter_1.c
  2. +67
    -0
      chapters/chapter_3.c
  3. +20
    -0
      chapters/chapter_3.h
  4. +2
    -1
      compile.sh
  5. +3
    -0
      xhartae.c

+ 1
- 1
chapters/chapter_1.c Voir le fichier

@@ -209,7 +209,7 @@ int file_type (char * name) {
}

void * file_record (char * name) {
int file = -1;
int file = -1; // You can also initialize local variables in this way.
int size = -1;
char * data = NULL;



+ 67
- 0
chapters/chapter_3.c Voir le fichier

@@ -0,0 +1,67 @@
/*
Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic

Xhartae is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version.
It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3.
*/

#ifndef CHAPTER_3_SOURCE
#define CHAPTER_3_SOURCE

#include "chapter_3.h"

void print (char * format, ...) {
va_list argument_array;

int offset, length;

int integer;
char * string;
double ieee754;

length = string_length (format);

va_start (argument_array, format);

for (offset = 0; offset != length; ++offset) {
if (format [offset] == '%') {
++offset;
if (format [offset] == '%') {
out ("%", 1);
} else if (format [offset] == 'i') {
integer = va_arg (argument_array, int);
echo (number_to_string (integer));
} else if (format [offset] == 'F') {
ieee754 = va_arg (argument_array, double);
echo (number_to_string ((int) ieee754));
} else if (format [offset] == 's') {
string = va_arg (argument_array, char *);
echo (string);
} else {
out ("?", 1);
}
} else if (format [offset] == '/') {
++offset;
if (format [offset] == '/') {
out ("/", 1);
}
} else {
out (& format [offset], 1);
}
}

va_end (argument_array);
}

void file_print (char * format, ...) {
(void) format;
return;
}

void string_print (char * format, ...) {
(void) format;
return;
}

#endif

+ 20
- 0
chapters/chapter_3.h Voir le fichier

@@ -0,0 +1,20 @@
/*
Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic

Xhartae is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version.
It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3.
*/

#ifndef CHAPTER_3_HEADER
#define CHAPTER_3_HEADER

#include <stdarg.h>

#include "chapter_0.h"

extern void print (char * format, ...);
extern void file_print (char * format, ...);
extern void string_print (char * format, ...);

#endif

+ 2
- 1
compile.sh Voir le fichier

@@ -5,9 +5,10 @@ set -xe
gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -c -o chapters/chapter_0.o chapters/chapter_0.c
gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -c -o chapters/chapter_1.o chapters/chapter_1.c
gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -c -o chapters/chapter_2.o chapters/chapter_2.c
gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -c -o chapters/chapter_3.o chapters/chapter_3.c

gcc -g -Wall -Wextra -Wpedantic -Werror -O0 -c -o xhartae.o xhartae.c

gcc -o xhartae xhartae.o chapters/chapter_0.o chapters/chapter_1.o chapters/chapter_2.o
gcc -o xhartae xhartae.o chapters/chapter_0.o chapters/chapter_1.o chapters/chapter_2.o chapters/chapter_3.o

exit

+ 3
- 0
xhartae.c Voir le fichier

@@ -9,6 +9,7 @@ It is distributed in the hope that it will be useful or harmful, it really depen
#include "chapters/chapter_0.h"
#include "chapters/chapter_1.h"
#include "chapters/chapter_2.h"
#include "chapters/chapter_3.h"

/*
About this "book":
@@ -129,5 +130,7 @@ int main (int argc, char * * argv) {
curses_synchronize ();
}

print ("%F\n%s\n%i\n", 69.1, "Heyo", 420);

return (EXIT_SUCCESS);
}

Chargement…
Annuler
Enregistrer