diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/ini_file_create.c | 17 | ||||
| -rw-r--r-- | examples/ini_file_read.c | 2 |
2 files changed, 7 insertions, 12 deletions
diff --git a/examples/ini_file_create.c b/examples/ini_file_create.c index 8910e9f..e1cfd21 100644 --- a/examples/ini_file_create.c +++ b/examples/ini_file_create.c @@ -6,6 +6,7 @@ #include <ctype.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include "../ini_file.h" @@ -14,22 +15,14 @@ /* This function reads a string of size MAX_STRING_SIZE from stdin. * It returns 0 if no valid string was retrieved. */ int get_string_from_stdin(const char *const prompt, char *string) { - int i, empty = 0; fputs(prompt, stdout); if (fgets(string, MAX_STRING_SIZE, stdin) == NULL) { return 0; } - /* Replace \n characters for \0 and check if string is empty (only composed of spaces) */ - for (i = 0; string[i] != '\0'; i++) { - if (string[i] == '\n') { - string[i] = '\0'; - break; - } - if (!isspace(string[i])) { - empty = 1; - } - } - return empty; + /* Replace space and new line characters by \0 */ + string[strcspn(string, " \t\r\n")] = '\0'; + /* Check if string is empty */ + return (string[0] != '\0'); } /*------------------------------------------------------------------------------ diff --git a/examples/ini_file_read.c b/examples/ini_file_read.c index 4f660ae..b54bebd 100644 --- a/examples/ini_file_read.c +++ b/examples/ini_file_read.c @@ -31,6 +31,8 @@ int main(const int argc, const char **const argv) { } printf("\nThe properties retrieved from the the ini file \"%s\" are:\n\n", argv[1]); ini_file_print_to(ini_file, stdout); + printf("\nCheck out this information of the INI file data structure:\n"); + ini_file_info(ini_file); ini_file_free(ini_file); return EXIT_SUCCESS; } |
