Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-----------main.c-----------*/
- #include <stdio.h>
- #include "text.h"
- #include "mem.h"
- int main (int argc, char** argv){
- char* string = NULL;
- string = mem_alloc (BUFFER * sizeof (char));
- fgets (string, BUFFER, stdin);
- if (string [strlen (string) - 1] == '\n')
- string [strlen (string) - 1] = '\0';
- printf ("The string is: %s\n", string);
- string = invert_string (string);
- printf ("The inverted string is: %s\n", string);
- free (string);
- return 0;
- }
- /*-----------text.c-----------*/
- #include <stdio.h>
- #include "text.h"
- #include "mem.h"
- /*****Invert String*****/
- char* invert_string (char* string){
- char *tmp_str = NULL;
- short int len = 0, i = 0;
- len = strlen (string);
- tmp_str = mem_alloc (BUFFER * sizeof (char));
- for (i = len; i >= 0; i--)
- tmp_str [len - i] = string [i - 1];
- tmp_str [len + 1] = '\0';
- string = tmp_str;
- //free (tmp_str);
- return tmp_str;
- }
- /*-----------text.h-----------*/
- #pragma once
- #include <string.h>
- #define BUFFER 256
- char* invert_string (char* string);
- /*-----------mem.c-----------*/
- #include "mem.h"
- /*****Memory Control*****/
- int mem_error = MEM_ERROR_OK;
- void* mem_alloc (const size_t size){
- void* result;
- if ((result = malloc(size)) == NULL){
- mem_error = MEM_ERROR_NO_MEMORY;
- }
- return result;
- }
- int mem_get_error(void){
- return mem_error;
- }
- int mem_clear_error(void){
- return mem_error = MEM_ERROR_OK;
- }
- /*-----------mem.h-----------*/
- #pragma once
- #include <stdlib.h>
- #define MEM_ERROR_OK 0
- #define MEM_ERROR_NO_MEMORY -1
- void* mem_alloc(const size_t size);
- int mem_get_error(void);
- int mem_clear_error(void);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement