Skip to content

Commit 785bae5

Browse files
committed
Edited last parts of the C function examples.
1 parent 45b007b commit 785bae5

File tree

1 file changed

+60
-47
lines changed

1 file changed

+60
-47
lines changed

src/lib.rs

+60-47
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,14 @@ use libc::c_uint;
371371
///
372372
/// // handling error and printing the result.
373373
/// if (!tcmb_evds_c_is_error(data_result)) { printf("\nNO ERROR!\n"); };
374-
///
375-
/// fwrite(data_result.output_ptr, data_result.string_capacity, 1, stdout);
376-
/// fflush(stdout);
377-
///
378374
/// printf("\nError: %s", tcmb_evds_c_is_error(data_result) ? "true" : "false");
379-
///
380-
///
381-
/// free(data_result.output_ptr);
375+
///
376+
/// char* data_result_message = calloc(data_result.string_capacity, sizeof(char));
377+
/// memmove(data_result_message, data_result.output_ptr, data_result.string_capacity * sizeof(char));
378+
///
379+
/// printf("%s", data_result_message);
380+
///
381+
/// free(data_result_message);
382382
///
383383
/// return 0;
384384
/// }
@@ -498,15 +498,19 @@ pub extern "C" fn tcmb_evds_c_get_data(
498498
///
499499
///
500500
/// // handling error and printing the result.
501-
/// if (advanced_data_result.error_type == NoError) { printf("\nNO ERROR!\n"); };
502-
///
503-
/// fwrite(advanced_data_result.output_ptr, advanced_data_result.string_capacity, 1, stdout);
504-
/// fflush(stdout);
505-
///
501+
/// if (!tcmb_evds_c_is_error(advanced_data_result)) { printf("\nNO ERROR!\n"); };
506502
/// printf("\nError: %s", tcmb_evds_c_is_error(advanced_data_result) ? "true" : "false");
507-
///
503+
///
504+
/// char* advanced_data_result_message = calloc(advanced_data_result.string_capacity, sizeof(char));
505+
/// memmove(
506+
/// advanced_data_result_message,
507+
/// advanced_data_result.output_ptr,
508+
/// advanced_data_result.string_capacity * sizeof(char)
509+
/// );
508510
///
509-
/// free(advanced_data_result.output_ptr);
511+
/// printf("%s", advanced_data_result_message);
512+
///
513+
/// free(advanced_data_result_message);
510514
///
511515
/// return 0;
512516
/// }
@@ -633,7 +637,7 @@ pub extern "C" fn tcmb_evds_c_get_advanced_data(
633637
///
634638
///
635639
/// // requesting data.
636-
/// TcmbEvdsResult data_group_result =
640+
/// TcmbEvdsResult data_group =
637641
/// tcmb_evds_c_get_data_group(
638642
/// data_group,
639643
/// date,
@@ -644,15 +648,15 @@ pub extern "C" fn tcmb_evds_c_get_advanced_data(
644648
///
645649
///
646650
/// // handling error and printing the result.
647-
/// if (data_group_result.error_type == NoError) { printf("\nNO ERROR!\n"); };
648-
///
649-
/// fwrite(data_group_result.output_ptr, data_group_result.string_capacity, 1, stdout);
650-
/// fflush(stdout);
651-
///
652-
/// printf("\nError: %s", tcmb_evds_c_is_error(data_group_result) ? "true" : "false");
653-
///
651+
/// if (!tcmb_evds_c_is_error(data_group)) { printf("\nNO ERROR!\n"); };
652+
/// printf("\nError: %s", tcmb_evds_c_is_error(data_group) ? "true" : "false");
653+
///
654+
/// char* data_group_message = calloc(data_group.string_capacity, sizeof(char));
655+
/// memmove(data_group_message, data_group.output_ptr, data_group.string_capacity * sizeof(char));
656+
///
657+
/// printf("%s", data_group_message);
654658
///
655-
/// free(data_group_result.output_ptr);
659+
/// free(data_group_message);
656660
///
657661
/// return 0;
658662
/// }
@@ -743,14 +747,15 @@ pub extern "C" fn tcmb_evds_c_get_data_group(
743747
///
744748
///
745749
/// // handling error and printing the result.
746-
/// if (categories.error_type == NoError) { printf("\nNO ERROR!\n"); };
747-
///
748-
/// fwrite(categories.output_ptr, categories.string_capacity, 1, stdout);
749-
///
750+
/// if (!tcmb_evds_c_is_error(categories)) { printf("\nNO ERROR!\n"); };
750751
/// printf("\nError: %s", tcmb_evds_c_is_error(categories) ? "true" : "false");
752+
///
753+
/// char* categories_message = calloc(categories.string_capacity, sizeof(char));
754+
/// memmove(categories_message, categories.output_ptr, categories.string_capacity * sizeof(char));
755+
///
756+
/// printf("%s", categories_message);
751757
///
752-
///
753-
/// free(categories.output_ptr);
758+
/// free(categories_message);
754759
///
755760
/// return 0;
756761
/// }
@@ -815,19 +820,30 @@ pub extern "C" fn tcmb_evds_c_get_categories(
815820
///
816821
///
817822
/// // requesting data.
818-
/// TcmbEvdsResult advanced_data_group = tcmb_evds_c_get_advanced_data_group(mode, code, api_key, return_format, ascii_mode);
823+
/// TcmbEvdsResult advanced_data_group =
824+
/// tcmb_evds_c_get_advanced_data_group(
825+
/// mode,
826+
/// code,
827+
/// api_key,
828+
/// return_format,
829+
/// ascii_mode
830+
/// );
819831
///
820832
///
821833
/// // handling error and printing the result.
822-
/// if (advanced_data_group.error_type == NoError) { printf("\nNO ERROR!\n"); };
823-
///
824-
/// fwrite(advanced_data_group.output_ptr, advanced_data_group.string_capacity, 1, stdout);
825-
/// fflush(stdout);
826-
///
834+
/// if (!tcmb_evds_c_is_error(advanced_data_group)) { printf("\nNO ERROR!\n"); };
827835
/// printf("\nError: %s", tcmb_evds_c_is_error(advanced_data_group) ? "true" : "false");
836+
///
837+
/// char* advanced_data_group_message = calloc(advanced_data_group.string_capacity, sizeof(char));
838+
/// memmove(
839+
/// advanced_data_group_message,
840+
/// advanced_data_group.output_ptr,
841+
/// advanced_data_group.string_capacity * sizeof(char)
842+
/// );
843+
///
844+
/// printf("%s", advanced_data_group_message);
828845
///
829-
///
830-
/// free(advanced_data_group.output_ptr);
846+
/// free(advanced_data_group_message);
831847
///
832848
/// return 0;
833849
/// }
@@ -902,15 +918,15 @@ pub extern "C" fn tcmb_evds_c_get_advanced_data_group(
902918
///
903919
///
904920
/// // handling error and printing the result.
905-
/// if (series_list.error_type == NoError) { printf("\nNO ERROR!\n"); };
906-
///
907-
/// fwrite(series_list.output_ptr, series_list.string_capacity, 1, stdout);
908-
/// fflush(stdout);
909-
///
921+
/// if (!tcmb_evds_c_is_error(series_list)) { printf("\nNO ERROR!\n"); };
910922
/// printf("\nError: %s", tcmb_evds_c_is_error(series_list) ? "true" : "false");
923+
///
924+
/// char* series_list_message = calloc(series_list.string_capacity, sizeof(char));
925+
/// memmove(series_list_message, series_list.output_ptr, series_list.string_capacity * sizeof(char));
926+
///
927+
/// printf("%s", series_list_message);
911928
///
912-
///
913-
/// free(series_list.output_ptr);
929+
/// free(series_list_message);
914930
///
915931
/// return 0;
916932
/// }
@@ -956,9 +972,6 @@ pub extern "C" fn tcmb_evds_c_get_series_list(
956972
///
957973
/// // handling error.
958974
/// printf("\nError: %s", tcmb_evds_c_is_error(series_list) ? "true" : "false");
959-
///
960-
///
961-
/// free(series_list.output_ptr);
962975
/// ```
963976
#[no_mangle]
964977
pub extern "C" fn tcmb_evds_c_is_error(result: TcmbEvdsResult) -> bool {

0 commit comments

Comments
 (0)