在C中添加/显示多维char数组的问题

时间:2016-07-28 13:58:55

标签: c arrays multidimensional-array

我在多维char数组中添加和显示值时遇到了困难。我接受用户的天数和各种费用金额,并希望将它们添加到我的char数组中。 像这样dayWise[day_1][total_expense_on_that_day];

这是我写的代码,请告诉我哪里出错了。

char dayWise[days_count][opening_bal_bk][15]; // Multidimensional array
printf("\nNumber of Days: %d\n", days_count);

for(i = 1; i <= days_count; i++) {
    printf("\n\t");

    printf("\nOpening Balance for Day %d is: %d", i, opening_bal_bk);
    printf("\n\t");

    printf("Day %d \n\t", i);
    printf("---------------");

    printf("\n\tFood: ");
    food_amount = num_valid();

    while(food_amount > opening_bal_bk) {
        printf("Food amount exceeding balance,enter again!");
        printf("\n\tFood: ");
        food_amount = num_valid();
    }
    opening_bal_bk -= food_amount;

    printf("\n\tTravel: ");
    travel_amount = num_valid();
    while(travel_amount > opening_bal_bk) {
        printf("Travel amount exceeding balance,enter again!");
        printf("\n\tTravel: ");
        travel_amount = num_valid();
    }
    opening_bal_bk -= travel_amount;



    dayWise[i][opening_bal_bk]; //adding to array here

0 个答案:

没有答案