Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "util_converter.h"
- #include "csv_converter.h"
- #include "hulke.h"
- void open_file(fp_ptr, filename, header)
- FILE** fp_ptr;
- const char* filename,
- * header;
- {
- if(IS_NOT_NULL(*fp_ptr = fopen(filename, "w"))) {
- fprintf(*fp_ptr,"%s\n",header);
- } else {
- printf("Erro ao abrir o arquivo: \"%s\"\n", filename);
- exit(1);
- }
- }
- static int split(string, new_string, delimiter)
- char* string,
- * new_string;
- const char* delimiter;
- {
- register int i = 0;
- static char* last_string;
- if(IS_NULL(string))
- if(IS_NOT_NULL(last_string))
- string = last_string;
- while(IS_NOT_NUL(*string)) {
- while(*string != *delimiter && IS_NOT_NUL(*string))
- *new_string++ = *string++;
- while(string[i] == delimiter[i] && IS_NOT_NUL(string[i]) && IS_NOT_NUL(delimiter[i]))
- i++;
- if(IS_NUL(string[i]) || IS_NUL(delimiter[i])) {
- if(IS_NUL(string[i]))
- last_string = NULL;
- else
- last_string = string + i;
- *new_string = NUL;
- return TRUE;
- } else
- while(i) {
- *new_string++ = *string++;
- i--;
- }
- }
- return FALSE;
- }
- #define QUESTION_SEPARATOR " - "
- #define TEACHER_SEPARATOR "/ "
- #define DISCIPLINE_SEPARATOR ""
- int extract_question_teacher_discipline(string_to_extract, string_question, string_teacher, string_discipline)
- char* string_to_extract,
- * string_question,
- * string_teacher,
- * string_discipline;
- {
- if(IS_NULL(string_to_extract)) {
- return FALSE;
- }
- //printf("%s -> %d\n", string_to_extract, csvc_record.length);
- if( split(string_to_extract, string_question, QUESTION_SEPARATOR) &&
- split(NULL, string_teacher, TEACHER_SEPARATOR) &&
- split(NULL, string_discipline, DISCIPLINE_SEPARATOR) )
- return TRUE;
- return FALSE;
- }
- int find_in_array(string_to_search, array_to_be_searched, length_of_array)
- char* string_to_search,
- (* array_to_be_searched)[300];
- int length_of_array;
- {
- register int i=0;
- for(i = 0; i <= length_of_array; i++) {
- if(!strcmp(string_to_search, array_to_be_searched[i])) {
- return i+1;
- }
- }
- return EOF;
- }
- void itoa(int_number, string_number)
- int int_number;
- char* string_number;
- {
- int string_length = 0,
- original_int_number = int_number,
- i = 0;
- do {
- string_length++;
- } while(int_number /= 10);
- string_number[string_length] = NUL;
- do {
- string_number[--string_length] = original_int_number % 10 + '0';
- } while(original_int_number /= 10);
- }
Advertisement
Add Comment
Please, Sign In to add comment