uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

commit 43e84fc9e2a5fca6741d72e9d080ec7a1459dff7
parent cefde2e4590048c9e9991ee5301101f0de32c437
Author: Christos Margiolis <christos@margiolis.net>
Date:   Thu,  7 May 2020 19:25:36 +0300

updated submodule

Diffstat:
Massignment-1.5-arrays-pointers-files/minecurses/README.md | 3+--
Massignment-1.5-arrays-pointers-files/minecurses/bin/minecurses | 0
Massignment-1.5-arrays-pointers-files/minecurses/log/session.txt | 8++++----
Massignment-1.5-arrays-pointers-files/minecurses/obj/audio.o | 0
Massignment-1.5-arrays-pointers-files/minecurses/obj/gameplay.o | 0
Massignment-1.5-arrays-pointers-files/minecurses/obj/main.o | 0
Massignment-1.5-arrays-pointers-files/minecurses/obj/minesweeper.o | 0
Massignment-1.5-arrays-pointers-files/minecurses/obj/navigation.o | 0
Massignment-1.5-arrays-pointers-files/minecurses/obj/outputs.o | 0
Massignment-1.5-arrays-pointers-files/minecurses/obj/settings.o | 0
Massignment-1.5-arrays-pointers-files/minecurses/obj/wins.o | 0
Massignment-1.5-arrays-pointers-files/minecurses/src/gameplay.c | 11++++++++---
Massignment-1.5-arrays-pointers-files/minecurses/src/gameplay.h | 2+-
Massignment-1.5-arrays-pointers-files/minecurses/src/main.c | 58+++++++++++++++++++++++++++++++++-------------------------
Massignment-1.5-arrays-pointers-files/minecurses/src/main.h | 4++++
Massignment-1.5-arrays-pointers-files/minecurses/src/minesweeper.c | 74+++++++++++++++++++++++++++++++++++++-------------------------------------
Massignment-1.5-arrays-pointers-files/minecurses/src/minesweeper.h | 16++++++++--------
Massignment-1.5-arrays-pointers-files/minecurses/src/outputs.c | 6+++---
Massignment-1.5-arrays-pointers-files/minecurses/src/outputs.h | 4+++-
Massignment-1.5-arrays-pointers-files/minecurses/src/settings.c | 2+-
Massignment-2.5-spreadsheets/bin/spreadsheets | 0
Massignment-2.5-spreadsheets/obj/main.o | 0
Massignment-2.5-spreadsheets/obj/xstring.o | 0
Dassignment-2.5-spreadsheets/src/vecstr/xstring.cpp | 226-------------------------------------------------------------------------------
Dassignment-2.5-spreadsheets/src/vecstr/xstring.h | 82-------------------------------------------------------------------------------
Massignment-2.5-spreadsheets/src/xstring.cpp | 3++-
26 files changed, 105 insertions(+), 394 deletions(-)

diff --git a/assignment-1.5-arrays-pointers-files/minecurses/README.md b/assignment-1.5-arrays-pointers-files/minecurses/README.md @@ -26,8 +26,7 @@ Additional controls ## To Do -* Add restart option -* Add quit option right when game opens +* Add more error checks * Load score log to ui * Add colors * Add UTF-8 support diff --git a/assignment-1.5-arrays-pointers-files/minecurses/bin/minecurses b/assignment-1.5-arrays-pointers-files/minecurses/bin/minecurses Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/log/session.txt b/assignment-1.5-arrays-pointers-files/minecurses/log/session.txt @@ -1,9 +1,9 @@ -Mine hit at position (3, 1) +Last mine defused at position (4, 2) Board overview -- 1 * 1 - -- 1 1 1 - -- - - - - +- - 1 1 1 +- - 1 * 1 +- - 1 1 1 - - - - - - - - - - diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/audio.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/audio.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/gameplay.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/gameplay.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/main.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/main.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/minesweeper.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/minesweeper.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/navigation.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/navigation.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/outputs.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/outputs.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/settings.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/settings.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/obj/wins.o b/assignment-1.5-arrays-pointers-files/minecurses/obj/wins.o Binary files differ. diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/gameplay.c b/assignment-1.5-arrays-pointers-files/minecurses/src/gameplay.c @@ -1,6 +1,7 @@ #include "gameplay.h" +#include "main.h" -void play_minesweeper(WINDOW *gamew, Board *brd) +void play(WINDOW *gamew, Board *brd) { int mbx = 0, mby = 0; int gameover = FALSE; @@ -44,6 +45,10 @@ void play_minesweeper(WINDOW *gamew, Board *brd) case 'm': handle_menu(gamew, brd); break; + case 'r': + reset(brd); + init_game(gamew, brd); + break; default: break; } } while (((mby >= 0 && mby < brd->rows) && (mbx >= 0 && mbx < brd->cols)) && @@ -110,13 +115,13 @@ void handle_gameover(WINDOW *gamew, Board *brd, int ymid, int xmid, int mby, int box(gamew, 0, 0); print_board(gamew, brd); wrefresh(gamew); - session_write(brd, mbx, mby, "lost"); + session_write(brd, mbx, mby, GAME_LOST); } void handle_win(WINDOW *gamew, Board *brd, int ymid, int xmid, int mby, int mbx, int ndefused) { game_won(gamew, ymid, xmid); getchar(); - session_write(brd, mbx, mby, "won"); + session_write(brd, mbx, mby, GAME_WON); score_write(ndefused, brd->rows, brd->cols); } diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/gameplay.h b/assignment-1.5-arrays-pointers-files/minecurses/src/gameplay.h @@ -23,7 +23,7 @@ #define VOLUME_DOWN '-' #define QUIT 'q' -void play_minesweeper (struct _win_st* gamew, Board *brd); +void play (struct _win_st* gamew, Board *brd); int open_cell (struct _win_st* gamew, Board *brd, int mby, int mbx, int gameover); void handle_flags (struct _win_st* gamew, Board *brd, int mby, int mbx); void defuse_mine (struct _win_st* gamew, Board *brd, int mby, int mbx); diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/main.c b/assignment-1.5-arrays-pointers-files/minecurses/src/main.c @@ -6,39 +6,17 @@ #include "wins.h" #include <pthread.h> -static void clear_board(Board *brd) -{ - int i; - for (i = 0; i < brd->rows; i++) - { - free(brd->db[i]); - free(brd->mb[i]); - } - free(brd->db); - free(brd->mb); -} - int main(int argc, char **argv) { Board brd; init_curses(); - echo(); - brd.cols = set_cols(); - brd.rows = set_rows(); - brd.nmines = set_nmines(brd.rows * brd.cols); - noecho(); - options_menu(); - erase(); - refresh(); - + reset(&brd); WINDOW *gamew = game_win(brd.rows, brd.cols); - brd.db = init_dboard(gamew, brd.cols, brd.rows); - brd.mb = init_mboard(gamew, brd.cols, brd.rows, brd.nmines); - + init_game(gamew, &brd); pthread_t audiothread; long threadid = 1; pthread_create(&audiothread, NULL, play_audio, (void *)threadid); - play_minesweeper(gamew, &brd); + play(gamew, &brd); pthread_cancel(audiothread); clear_board(&brd); @@ -47,3 +25,33 @@ int main(int argc, char **argv) return 0; } + +void reset(Board *brd) +{ + echo(); + brd->cols = set_cols(); + brd->rows = set_rows(); + brd->nmines = set_nmines(brd->rows * brd->cols); + noecho(); + options_menu(); + erase(); + refresh(); +} + +void init_game(WINDOW *gamew, Board *brd) +{ + brd->db = init_db(gamew, brd->cols, brd->rows); + brd->mb = init_mb(gamew, brd->cols, brd->rows, brd->nmines); +} + +void clear_board(Board *brd) +{ + int i; + for (i = 0; i < brd->rows; i++) + { + free(brd->db[i]); + free(brd->mb[i]); + } + free(brd->db); + free(brd->mb); +} diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/main.h b/assignment-1.5-arrays-pointers-files/minecurses/src/main.h @@ -17,4 +17,8 @@ typedef struct int rows, cols, nmines; } Board; +void reset(Board *brd); +void init_game(WINDOW *gamew, Board *brd); +void clear_board(Board *brd); + #endif /* MAIN_H */ diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/minesweeper.c b/assignment-1.5-arrays-pointers-files/minecurses/src/minesweeper.c @@ -1,39 +1,39 @@ #include "minesweeper.h" -char **init_dboard(WINDOW *gamew, int cols, int rows) +char **init_db(WINDOW *gamew, int cols, int rows) { int i; - char **dboard = (char **)malloc(rows * sizeof(char *)); + char **db = (char **)malloc(rows * sizeof(char *)); for (i = 0; i < rows; i++) - dboard[i] = (char *)malloc(cols); + db[i] = (char *)malloc(cols); - if (dboard == NULL) + if (db == NULL) { - mvprintw(1, 1, "Error, not enough memory, exiting..."); + mvprintw(0, 0, "Error, not enough memory, exiting..."); refresh(); exit(EXIT_FAILURE); } - else fill_dboard(dboard, cols, rows); + else fill_db(db, cols, rows); - return dboard; + return db; } -void fill_dboard(char **dboard, int cols, int rows) +void fill_db(char **db, int cols, int rows) { int i, j; for (i = 0; i < rows; i++) for (j = 0; j < cols; j++) - dboard[i][j] = BLANK; + db[i][j] = BLANK; } -char **init_mboard(WINDOW *gamew, int cols, int rows, int nmines) +char **init_mb(WINDOW *gamew, int cols, int rows, int nmines) { int i; - char **mboard = (char **)malloc(rows * sizeof(char *)); + char **mb = (char **)malloc(rows * sizeof(char *)); for (i = 0; i < rows; i++) - mboard[i] = (char *)malloc(cols); + mb[i] = (char *)malloc(cols); - if (mboard == NULL) + if (mb == NULL) { mvprintw(0, 0, "Error, not enough memory, exiting..."); refresh(); @@ -41,15 +41,15 @@ char **init_mboard(WINDOW *gamew, int cols, int rows, int nmines) } else { - place_mines(mboard, cols, rows, nmines); - add_adj(mboard, cols, rows); - fill_spaces(mboard, cols, rows, nmines); + place_mines(mb, cols, rows, nmines); + add_adj(mb, cols, rows); + fill_spaces(mb, cols, rows, nmines); } - return mboard; + return mb; } -void place_mines(char **mboard, int cols, int rows, int nmines) +void place_mines(char **mb, int cols, int rows, int nmines) { int i, wrand, hrand; srand(time(NULL)); @@ -57,22 +57,22 @@ void place_mines(char **mboard, int cols, int rows, int nmines) { wrand = rand() % rows; hrand = rand() % cols; - mboard[wrand][hrand] = MINE; + mb[wrand][hrand] = MINE; } } -void add_adj(char **mboard, int cols, int rows) +void add_adj(char **mb, int cols, int rows) { int i, j; for (i = 0; i < rows; i++) for (j = 0; j < cols; j++) - if (!is_mine(mboard, i, j)) - mboard[i][j] = adj_mines(mboard, i, j, cols, rows) + '0'; + if (!is_mine(mb, i, j)) + mb[i][j] = adj_mines(mb, i, j, cols, rows) + '0'; } -int is_mine(char **mboard, int row, int col) +int is_mine(char **mb, int row, int col) { - return (mboard[row][col] == MINE) ? TRUE : FALSE; + return (mb[row][col] == MINE) ? TRUE : FALSE; } int outof_bounds(int row, int col, int cols, int rows) @@ -80,27 +80,27 @@ int outof_bounds(int row, int col, int cols, int rows) return (row < 0 || row > rows-1 || col < 0 || col > cols-1) ? TRUE : FALSE; } -uint8_t adj_mines(char **mboard, int row, int col, int cols, int rows) +uint8_t adj_mines(char **mb, int row, int col, int cols, int rows) { - int8_t nadj = 0; + uint8_t nadj = 0; - if (!outof_bounds(row, col-1, cols, rows) && mboard[row][col-1] == MINE) nadj++; // north - if (!outof_bounds(row, col+1, cols, rows) && mboard[row][col+1] == MINE) nadj++; // south - if (!outof_bounds(row+1, col, cols, rows) && mboard[row+1][col] == MINE) nadj++; // east - if (!outof_bounds(row-1, col, cols, rows) && mboard[row-1][col] == MINE) nadj++; // west - if (!outof_bounds(row+1, col-1, cols, rows) && mboard[row+1][col-1] == MINE) nadj++; // north-east - if (!outof_bounds(row-1, col-1, cols, rows) && mboard[row-1][col-1] == MINE) nadj++; // north-west - if (!outof_bounds(row+1, col+1, cols, rows) && mboard[row+1][col+1] == MINE) nadj++; // south-east - if (!outof_bounds(row-1, col+1, cols, rows) && mboard[row-1][col+1] == MINE) nadj++; // south-west + if (!outof_bounds(row, col-1, cols, rows) && mb[row][col-1] == MINE) nadj++; // north + if (!outof_bounds(row, col+1, cols, rows) && mb[row][col+1] == MINE) nadj++; // south + if (!outof_bounds(row+1, col, cols, rows) && mb[row+1][col] == MINE) nadj++; // east + if (!outof_bounds(row-1, col, cols, rows) && mb[row-1][col] == MINE) nadj++; // west + if (!outof_bounds(row+1, col-1, cols, rows) && mb[row+1][col-1] == MINE) nadj++; // north-east + if (!outof_bounds(row-1, col-1, cols, rows) && mb[row-1][col-1] == MINE) nadj++; // north-west + if (!outof_bounds(row+1, col+1, cols, rows) && mb[row+1][col+1] == MINE) nadj++; // south-east + if (!outof_bounds(row-1, col+1, cols, rows) && mb[row-1][col+1] == MINE) nadj++; // south-west return nadj; } -void fill_spaces(char **mboard, int cols, int rows, int nmines) +void fill_spaces(char **mb, int cols, int rows, int nmines) { int i, j; for (i = 0; i < rows; i++) for (j = 0; j < cols; j++) - if (mboard[i][j] != MINE && mboard[i][j] == '0') - mboard[i][j] = '-'; + if (mb[i][j] != MINE && mb[i][j] == '0') + mb[i][j] = '-'; } diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/minesweeper.h b/assignment-1.5-arrays-pointers-files/minecurses/src/minesweeper.h @@ -10,14 +10,14 @@ #define BLANK ' ' #define MINE '*' -char **init_dboard (struct _win_st* gamew, int cols, int rows); -void fill_dboard (char **dboard, int cols, int rows); -char **init_mboard (struct _win_st* gamew, int cols, int rows, int nmines); -void place_mines (char **mboard, int cols, int rows, int nmines); -void add_adj (char **mboard, int cols, int rows); -int is_mine (char **mboard, int row, int col); +char **init_db (struct _win_st* gamew, int cols, int rows); +void fill_db (char **db, int cols, int rows); +char **init_mb (struct _win_st* gamew, int cols, int rows, int nmines); +void place_mines (char **mb, int cols, int rows, int nmines); +void add_adj (char **mb, int cols, int rows); +int is_mine (char **mb, int row, int col); int outof_bounds (int row, int col, int rows, int cols); -uint8_t adj_mines (char **mboard, int row, int col, int cols, int rows); -void fill_spaces (char **mboard, int cols, int rows, int nmines); +uint8_t adj_mines (char **mb, int row, int col, int cols, int rows); +void fill_spaces (char **mb, int cols, int rows, int nmines); #endif /* MINESWEEPER_H */ diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/outputs.c b/assignment-1.5-arrays-pointers-files/minecurses/src/outputs.c @@ -37,7 +37,7 @@ void session_info(int mbx, int mby, int xmid, int ndefused, int nmines) mvprintw(0, XMAX-strlen("m Controls"), "m Controls"); } -void session_write(Board *brd, int hitrow, int hitcol, const char *status) +void session_write(Board *brd, int hitrow, int hitcol, State state) { int i, j; FILE *fsession = fopen(SESSION_PATH, "w"); @@ -49,7 +49,7 @@ void session_write(Board *brd, int hitrow, int hitcol, const char *status) } else { - strcmp(status, "won") + state == GAME_WON ? fprintf(fsession, "Mine hit at position (%d, %d)\n\n", hitrow+1, hitcol+1) : fprintf(fsession, "Last mine defused at position (%d, %d)\n\n", hitrow+1, hitcol+1); fprintf(fsession, "Board overview\n\n"); @@ -76,7 +76,7 @@ void score_write(int ndefused, int cols, int rows) else { fprintf(scorelog, "%s,%d,%dx%d\n", playername, ndefused, cols, rows); - sort_scorelog(scorelog); // pending + sort_scorelog(scorelog); clrtoeol(); show_scorelog(scorelog); mvprintw(0, 0, "New score written to score log"); diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/outputs.h b/assignment-1.5-arrays-pointers-files/minecurses/src/outputs.h @@ -7,10 +7,12 @@ #define SESSION_PATH "log/session.txt" #define SCORE_LOG_PATH "log/scorelog.csv" +typedef enum {GAME_WON, GAME_LOST} State; + void print_board (struct _win_st* gamew, Board *brd); void print_grid (struct _win_st* gamew, int rows, int cols); void session_info (int mbx, int mby, int xmid, int ndefused, int nmines); -void session_write (Board *brd, int hitrow, int hitcol, const char *status); +void session_write (Board *brd, int hitrow, int hitcol, State state); void score_write (int ndefused, int cols, int rows); char *get_pname (void); void sort_scorelog (FILE *scorelog); diff --git a/assignment-1.5-arrays-pointers-files/minecurses/src/settings.c b/assignment-1.5-arrays-pointers-files/minecurses/src/settings.c @@ -31,7 +31,7 @@ int set_nmines(int dimensions) int nmines; do { - mvprintw(YMAX-2, 1, "Mines (Max = %d): ", dimensions-15); // -10 so the player has a chance to win + mvprintw(YMAX-2, 1, "Mines (Max = %d): ", dimensions-15); refresh(); scanw("%d", &nmines); refresh(); diff --git a/assignment-2.5-spreadsheets/bin/spreadsheets b/assignment-2.5-spreadsheets/bin/spreadsheets Binary files differ. diff --git a/assignment-2.5-spreadsheets/obj/main.o b/assignment-2.5-spreadsheets/obj/main.o Binary files differ. diff --git a/assignment-2.5-spreadsheets/obj/xstring.o b/assignment-2.5-spreadsheets/obj/xstring.o Binary files differ. diff --git a/assignment-2.5-spreadsheets/src/vecstr/xstring.cpp b/assignment-2.5-spreadsheets/src/vecstr/xstring.cpp @@ -1,226 +0,0 @@ -#include "xstring.h" - -namespace lab { -xstring::xstring() {} - -xstring::xstring(const char *s) {store(s);} - -xstring::~xstring() -{ - if (!str.empty()) str.clear(); -} - -xstring xstring::operator= (const xstring& s) -{ - if (this == &s) return *this; - if (!s.str.empty()) - { - this->str.clear(); - store(s.cstr()); - } - return *this; -} - -xstring xstring::operator= (const char *s) -{ - if (!strempty(s)) store(s); - return *this; -} - -xstring xstring::operator+ (const xstring& s) -{ - return xstring(strcat(this->cstr(), s.cstr())); -} - -xstring xstring::operator+ (const char *s) -{ - return xstring(strcat(this->cstr(), s)); -} - -xstring& xstring::operator+= (const xstring& s) -{ - store(s.cstr()); - return *this; -} - -xstring& xstring::operator+= (const char *s) -{ - store(s); - return *this; -} - -xstring& xstring::operator+= (char c) -{ - str.push_back(c); - return *this; -} - -bool xstring::operator== (const xstring& s) const -{ - return strcmp(this->cstr(), s.cstr()) == 0; -} - -bool xstring::operator== (const char *s) const -{ - return strcmp(this->cstr(), s) == 0; -} - -bool xstring::operator!= (const xstring& s) const -{ - return strcmp(this->cstr(), s.cstr()) != 0; -} - -bool xstring::operator!= (const char *s) const -{ - return strcmp(this->cstr(), s) != 0; -} - -bool xstring::operator< (const xstring& s) const -{ - return strlen(this->cstr()) < strlen(s.cstr()); -} - -bool xstring::operator< (const char *s) const -{ - return strlen(this->cstr()) < strlen(s); -} - -bool xstring::operator<= (const xstring& s) const -{ - return strlen(this->cstr()) <= strlen(s.cstr()); -} - -bool xstring::operator<= (const char *s) const -{ - return strlen(this->cstr()) <= strlen(s); -} - -bool xstring::operator> (const xstring& s) const -{ - return strlen(this->cstr()) > strlen(s.cstr()); -} - -bool xstring::operator> (const char *s) const -{ - return strlen(this->cstr()) > strlen(s); -} - -bool xstring::operator>= (const xstring& s) const -{ - return strlen(this->cstr()) >= strlen(s.cstr()); -} - -bool xstring::operator>= (const char *s) const -{ - return strlen(this->cstr()) >= strlen(s); -} - -char& xstring::operator[] (std::size_t i) -{ - try {if (i >= str.size()) throw i;} - catch (int i) {throw std::runtime_error("Out of bounds.");} - return str[i]; -} - -std::ostream& operator<< (std::ostream& stream, const xstring& s) -{ - return stream << s.cstr(); -} - -std::istream& operator>> (std::istream& stream, const xstring& s) -{ - return stream >> s.cstr(); -} - -void xstring::store(const char *s) -{ - str.insert(str.end(), s, s + strlen(s)); -} - -void xstring::store(const char *s, std::size_t i) -{ - str.insert(str.begin() + i, s, s + strlen(s)); -} - -xstring& xstring::append(const xstring& s) -{ - if (!strempty(s.cstr())) store(s.cstr()); - return *this; -} - -xstring& xstring::append(const xstring& s, std::size_t i) -{ - if (!strempty(s.cstr())) store(s.cstr(), i); - return *this; -} - -xstring& xstring::append(const char *s) -{ - if (!strempty(s)) store(s); - return *this; -} - -xstring& xstring::append(const char *s, std::size_t i) -{ - if (!strempty(s)) store(s, i); - return *this; -} - -xstring& xstring::append(char c) -{ - str.push_back(c); - return *this; -} - -char *xstring::cstr() const -{ - if (!str.empty()) - { - char *tmp = new char[str.size() + 1]; - for (std::size_t i = 0; i < str.size(); i++) - tmp[i] = str[i]; - tmp[str.size()] = '\0'; - return tmp; - } - else return new char[1]; -} - -std::size_t xstring::len() const -{ - return str.size(); -} - -void xstring::strclear() -{ - str.clear(); -} - -bool xstring::strempty(const char *s) const -{ - return strlen(s) == 0; -} - -std::istream& getline(std::istream& stream, xstring& s, char delim) -{ - char c; - s.strclear(); - while (stream.get(c) && c != '\n') - { - if (c == delim) break; - else s.append(c); - } - return stream; -} - -template<> const char *getformat<short>() {return "%hi";} -template<> const char *getformat<int>() {return "%d";} -template<> const char *getformat<long>() {return "%ld";} -template<> const char *getformat<long long>() {return "%lld";} -template<> const char *getformat<unsigned short>() {return "%hu";} -template<> const char *getformat<unsigned int>() {return "%u";} -template<> const char *getformat<unsigned long>() {return "%lu";} -template<> const char *getformat<unsigned long long>() {return "%llu";} -template<> const char *getformat<float>() {return "%f";} -template<> const char *getformat<double>() {return "%f";} -template<> const char *getformat<long double>() {return "%Lf";} -} diff --git a/assignment-2.5-spreadsheets/src/vecstr/xstring.h b/assignment-2.5-spreadsheets/src/vecstr/xstring.h @@ -1,82 +0,0 @@ -#ifndef XSTRING_H -#define XSTRING_H - -#include <algorithm> -#include <cstdlib> -#include <iostream> -#include <string.h> -#include <vector> - -namespace lab { -class xstring -{ - private: - std::vector<char> str; - - public: - xstring(); - xstring(const char *s); - ~xstring(); - - xstring operator= (const xstring& s); - xstring operator= (const char *s); - xstring operator+ (const xstring& s); - xstring operator+ (const char *s); - xstring& operator+= (const xstring& s); - xstring& operator+= (const char *s); - xstring& operator+= (char c); - bool operator== (const xstring& s) const; - bool operator== (const char *s) const; - bool operator!= (const xstring& s) const; - bool operator!= (const char *s) const; - bool operator< (const xstring& s) const; - bool operator< (const char *s) const; - bool operator<= (const xstring& s) const; - bool operator<= (const char *s) const; - bool operator> (const xstring& s) const; - bool operator> (const char *s) const; - bool operator>= (const xstring& s) const; - bool operator>= (const char *s) const; - char& operator[] (std::size_t i); - friend std::ostream& operator<< (std::ostream& stream, const xstring& s); - friend std::istream& operator>> (std::istream& stream, const xstring& s); - - xstring& append(const xstring& s); - xstring& append(const xstring& s, std::size_t i); - xstring& append(const char *s); - xstring& append(const char *s, std::size_t i); - xstring& append(char c); - - char *cstr() const; - std::size_t len() const; - void strclear(); - - private: - void store(const char *s); - void store(const char *s, std::size_t i); - bool strempty(const char *s) const; -}; - -std::istream& getline(std::istream& stream, xstring& s, char delim = '\n'); -template<typename T> xstring to_xstr(T val); -template<typename T> xstring to_xstr(const char *fs, T val); -template<typename T> const char *getformat(); - -template<typename T> -xstring to_xstr(T val) -{ - char buf[25]; - snprintf(buf, sizeof(buf), getformat<T>(), val); - return xstring(buf); -} - -template<typename T> -xstring to_xstr(const char *fs, T val) -{ - char buf[25]; - snprintf(buf, sizeof(buf), fs, val); - return xstring(buf); -} -} - -#endif /* XSTRING_H */ diff --git a/assignment-2.5-spreadsheets/src/xstring.cpp b/assignment-2.5-spreadsheets/src/xstring.cpp @@ -299,7 +299,8 @@ void xstring::clear() { if (!this->empty()) delete[] str; str = new char[1]; - *this = ""; + str[0] = '\0'; + //*this = ""; len = 0; }