online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include "burguer.h" int main (void) { tMenu m; tOrders o; tBurguer b; tIngredient i; int pos; init (&m, &o); b.id = 0; strcpy(b.name, "special"); b.ingredients=NULL; b.numIng=0; b.price=10.5; strcpy(i.name, "lettuce"); i.quantity = 100; add_ingredient (&b, i); strcpy(i.name, "onion"); i.quantity = 100; add_ingredient (&b, i); strcpy(i.name, "bacon"); i.quantity = 100; add_ingredient (&b, i); printf("\n number of ingredients = %d \n", b.numIng); for (pos=0; pos<b.numIng; pos++) printf("\n i=%d name=%s quantity=%d\n", pos, b.ingredients[pos].name, b.ingredients[pos].quantity); del_ingredient (&b, "lettuce", 50); del_ingredient (&b, "onion", 100); del_ingredient (&b, "bacon", 200); del_ingredient (&b, "mushroom", 20); printf("\n number of ingredients = %d \n", b.numIng); for (pos=0; pos<b.numIng; pos++) printf("\n i=%d name=%s quantity=%d\n", pos, b.ingredients[pos].name, b.ingredients[pos].quantity); return 0; }
#include "burguer.h" void init(tMenu *m, tOrders *o) { m = NULL; printf("[ OK ] Menu Initialized!\n"); o->orders = (tOrder *)malloc(sizeof(tOrder)); if (o->orders == NULL) printf("[ERROR] Unable to allocate memory for Orders"); printf("[ OK ] Orders Initialized!\n"); } void add_ingredient(tBurguer *b, tIngredient i) { int numIng = b->numIng; if (numIng == 0) { b->ingredients = (tIngredient *)malloc(sizeof(tIngredient)); if (b->ingredients == NULL) { printf("[ERROR]: Memory error\n"); } else { printf("[ OK ] Ingredients Initialized!\n"); b->ingredients[0] = i; b->numIng++; } } else { for (size_t pos = 0; pos < numIng; pos++) { const char *aux = b->ingredients[pos].name; if (!strcmp(b->ingredients[pos].name,i.name)) { b->ingredients[pos].quantity += i.quantity; printf("[ OK ] Ingredient \"%s\" added +%igrams", i.name, i.quantity); } else if (pos == numIng) { b->ingredients = (tIngredient *)realloc(b->ingredients, sizeof(tIngredient) + 1); if (b->ingredients == NULL) printf("[ERROR] Unable to allocate memory for ingredient"); else { b->ingredients[numIng] = i; numIng++; } } } } } bool del_ingredient(tBurguer *b, char *name, int quantity) { return 0; }
#include <stdlib.h> #include <string.h> #include <stdio.h> #define MAX_BURGER_TYPE 100 #define MAX_CHAR 20 typedef enum{false,true} bool; typedef char string[MAX_CHAR+1]; typedef struct { string name; int quantity; } tIngredient; typedef struct { int id; string name; int numIng; float price; tIngredient* ingredients; } tBurguer; typedef struct { int id; int burguer_id; int quantity; } tOrder; typedef struct { tOrder *orders; } tOrders; typedef struct { int *burguer_type[MAX_BURGER_TYPE]; } tMenu; void init(tMenu *m, tOrders *o); void add_ingredient(tBurguer *b, tIngredient i); bool del_ingredient(tBurguer *b, char *name, int quantity);

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue