PLEASE HELP ME!

+1 John Carlo Luy · January 19, 2016
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

#define BUFFERSIZE      256         
#define MAXENTRIES      256         
#define MAXCHOICES      256         
#define CATEGORYCOUNT   5           

typedef char String[BUFFERSIZE];

const static String FILENAMES[CATEGORYCOUNT] = {
  "config.txt",
    "menu.txt",
};

typedef struct Category {
    String name;
    String entries[MAXENTRIES];
    int count;
} Category;

void readCategoryEntries(const char *filename, Category *category);


int main() {
    Category categories[CATEGORYCOUNT] = {      
        {"Choose your champion:", {0}, 0},
        {"Choose your role:", {0}, 0},
        {"Choose your secondary role:", {0}, 0},
    };
    int choices[MAXCHOICES][CATEGORYCOUNT];     
    int choice_counter;                         
    int temp_choice;                            
    int curr_category;                          
    bool has_exit;                              
    int i, j;                                   

    for (i = 0; i < CATEGORYCOUNT; i++)
        readCategoryEntries(FILENAMES, &categories);

    choice_counter = 0;
    has_exit = false;
    while (!has_exit && choice_counter < MAXCHOICES) {
        curr_category = 0;

        for (i = 0; i < CATEGORYCOUNT; i++)
            choices[choice_counter] = -1;

        while (curr_category < CATEGORYCOUNT) {
            system("cls");

            for (i = 0; i < choice_counter; i++) {
                printf(" ");
                for (j = 0; j < CATEGORYCOUNT; j++)
            printf("[%s]", categories[j].entries[choices[j]]);
                printf("\n");
            }

            printf(" ");
            for (i = 0; i < curr_category; i++)
                printf("[%s]",
                       categories.entries[choices[choice_counter]]);
            printf("\n\n");

            printf("Category: %s\n", categories[curr_category].name);
            for (i = 0; i < categories[curr_category].count; i++) {
                if (choices[choice_counter][curr_category] == i)
                    printf("* ");
                else
                    printf("  ");
                printf("[%02d] - %s\n", i+1,
                       categories[curr_category].entries);
            }

            if (curr_category == 0)
                printf("  [%02d] - Exit\n", i+1);
            else
                printf("  [%02d] - Back\n", i+1);

            printf("Enter choice: ");
            scanf("%d", &temp_choice);
            temp_choice--;

            if (temp_choice == i) {
                if (curr_category == 0) {
                    has_exit = true;
                    break;
                } else {
                    curr_category--;
                }
            } else {
                choices[choice_counter][curr_category] = temp_choice;
                curr_category++;
            }
        }
        choice_counter++;
    }

    return EXIT_SUCCESS;
}

void readCategoryEntries(const char *filename, Category *category) {
    FILE *istream;      
    int line_count;     
    char dump;          

    
    if ((istream = fopen(filename, "r")) == NULL) {
        printf("error: Can't open %s\n", filename);
        exit(EXIT_FAILURE);
    }

    line_count = 0;     
    
    while (!feof(istream)) {
        
        fgets(category->entries[line_count], BUFFERSIZE, istream);

        if (category->entries[line_count][strlen(category->entries[line_count])-1] == '\n')
            category->entries[line_count][strlen(category->entries[line_count])-1] = '\0';

        line_count++;
    }

    category->count = line_count;

    fclose(istream);    
    return;
}


============================================================
My code can't open the file that all of the information is stored. Basically it is a menu that read every menu and submenu then write the history in the another notepad. Can someone help me? Please I'm begging you.
Note: You can edit my code or write your own.
THANK YOU!

Post a Reply

Replies

Oldest  Newest  Rating
0 Linguist Llama · January 19, 2016
Do you understand the warnings your compiler is emitting at you?
  • 1

C

106,965 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator