Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // myutils.h
- // Utils to handle C, make everything easly.
- // made by Artur 'hoOmE' Paiva <[email protected]>
- // Under GPLv3 - http://www.gnu.org/licenses/gpl.html
- // Define your os, can be "linux" or "windows".
- char OS[] = "linux";
- // Include basic input/output library and system utils.
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- // Declare some vars
- int null = NULL;
- int none = NULL;
- int false = 0;
- int true = 1;
- // Function to clear the screen
- int clear() {
- int returned = 1;
- if (!strcmp(OS,"linux")) {
- returned = system("clear");
- } else if (!strcmp(OS,"windows")) {
- returned = system("cls");
- }
- return(returned);
- }
- // Structure to a simple string
- typedef struct String {
- char *string;
- int size;
- } string;
- // Function to get a input
- char * input(char *text,int size) {
- printf("%s",text);
- size+=2;
- char input[size];
- fflush(stdin);
- fgets(input,size,stdin);
- char *input2 = malloc(size);
- strcpy(input2,input);
- strtok(input2, "\n");
- return(input2);
- }
- // Function to convert to int
- int toint(char *value) {
- return(atoi(value));
- }
- // Function to convert to char array
- char *tostring(int value) {
- char *str = malloc(1);
- sprintf(str, "%d", value);
- return(str);
- }
- // Function to print text
- int print(char *value) {
- printf("%s\n",value);
- }
- // Function to make a delay
- void delay(int time) {
- if(!strcmp(OS,"linux")) {
- sleep(time);
- } else if (!strcmp(OS,"windows")) {
- sleep(time*1000);
- }
- }
- // Function to pause
- int pause() {
- int returned = 1;
- if(!strcmp(OS,"linux")) {
- printf("\nPressione qualquer tecla para continuar...\n");
- returned = system("read null");
- } else if (!strcmp(OS,"windows")) {
- printf("\n");
- returned = system("pause");
- }
- return(returned);
- }
- // Function to create a menu
- int menu(char *titulo,char *items[],int opcoes) {
- int counter = 0;
- if (opcoes > 9) {
- opcoes = 9;
- }
- if (opcoes < 1) {
- opcoes = 1;
- }
- int resultado = 0;
- clear();
- if (!strcmp(OS,"linux")) {
- printf("\033[1;37m\t%s\t\n\n",titulo);
- } else {
- printf("\t%s\t\n\n",titulo);
- }
- while (counter < opcoes) {
- if (!strcmp(OS,"linux")) {
- printf("\033[1;33m%d =>\033[1;37m %s\n",counter+1,items[counter]);
- } else if (!strcmp(OS,"windows")) {
- printf("%d => %s",counter+1,items[counter]);
- }
- counter++;
- }
- resultado = toint(input("\nType an option > \033[0m",1));
- if (resultado > opcoes || resultado < 1) {
- print("You typed a unvalid option!");
- pause();
- menu(titulo,items,opcoes);
- } else {
- return(resultado);
- }
- }
- // Function to ajust the screen
- void screenfix() {
- if (!strcmp(OS,"linux")) {
- printf("\033[1;37m");
- } else if (!strcmp(OS,"windows")) {
- system("color 1F");
- }
- }
- // Print a vector
- void print_r(int *vetor,int size,char separator) {
- int counter = 0;
- while (counter < size) {
- printf("%d%c",vetor[counter],separator);
- counter++;
- }
- }
- // Dump the values from a vector
- void vardump(int *vetor, int size) {
- int counter = 0;
- printf("Array %p {\n",&vetor);
- while (counter < size) {
- printf("\t%d => %d\n",counter,vetor[counter]);
- counter++;
- }
- printf("}\n");
- }
- // Function that just "pass", useless in most cases, but here is
- void pass() {
- printf("");
- }
Advertisement
Add Comment
Please, Sign In to add comment