SD Card Question(Although possibly a pointer problem or Serial problem)

So I have this code below. i’m trying to read a series of bytes for a file on an sd card. The card reader checks out and works great on the demo files that are with the arduino and a few small read, write, read etc… files I wrote. Here is the issue I’m seeing. When the readIngredients() function is called, nothing prints to serial, not even the initial initialization print lines. When I remove the parameters to readIngredients, everything prints finr. but I think thats a sign of something failing.

the structs look like this they are in a header file that is included. all the constants are defined in the file too but, that is quite long so I wont bother posting it unless it makes a difference.

typedef struct {
  char name[NAME_SIZE];
  short amount;
} ingredient;

/* Drink data structure
    name - name of ingredient
    ingredient - list of ingredients in recipe
    numIngreds - number of ingreds for this drink

*/
typedef struct {
  char name[NAME_SIZE];
  ingredient ingred[MAX_INGREDS_PER_DRINK];
  int numIngreds;
} drink;

typedef struct {
  int pinNum;
  int state;
  } pin;

const pin PINS[NUM_PINS] = {{LCD_CTRL_0,OUTPUT},{LCD_CTRL_1,OUTPUT},
                    {PUMP1,OUTPUT},{PUMP2,OUTPUT},{PUMP3,OUTPUT},{PUMP4,OUTPUT},{PUMP5,OUTPUT},{PUMP6,OUTPUT}
                    };

And here is the file. pretty much the read ingredients funcition calls the readData function which reads a number of bytes from the file and places them into a string which then in readIngredients gets placed into the array of ingredients

Any comments or help are greatly appreciated… Ive been banging my head on this for many hours. I did write a similar program in C to just test my pointer logic, and it seemed to work, but removing all the code except for the function decleration still leads to the issues I’m experiencing.

#include "defs.h"
#include <SD.h>
#include <string.h>

// list of all possible ingredients  
  ingredient _ingredients[MAX_INGREDIENTS];

  // list of ingredients in the ingredient holders
  ingredient _selectedIngredients[MAX_INGREDS_PER_DRINK];

  // list of all possible drink recipes
  drink _drinks[MAX_DRINKS];


File myRecipeList;
File myConfig;
// drinkIndex -- currently selected Drink
// ingredIndex -- currently selected Ingredient holder
// numDrinks -- Number of Drinks that have been read from the SD Card
// numIngreds -- Number of Ingredients that have been read from the SD Card

 int drinkIndex = 0, ingredIndex = 0, 
          recipePageIndex = 0, numDrinks = 0, 
         numIngreds = 0, recipeIndex = 0;
//This should be moved to main so you can call all the crap with direct pointers         

void setup() {
   Serial.begin(9600);
   Serial.print("Begin");
  for (int i = 0 ; i < NUM_PINS; i++) {
    pinMode(PINS[i].pinNum, PINS[i].state);
    Serial.print(PINS[i].pinNum);
    Serial.print(":");
    Serial.print(PINS[i].state);   
    Serial.print("\n");
  }

 
  

     // Initialize SD Card
  if (!SD.begin(4)) {
    return; // fail if we can't
  } 


  
    myRecipeList = (SD.open("recipe.dat",FILE_READ)); 
    if (myRecipeList) {
    // Read ingredients first, then read recipes
    //Serial.print("File opened... reading ingredients \n");
    readIngredients((ingredient*)&_selectedIngredients,(ingredient*)&_ingredients);
    // Serial.print("File opened... reading recipes \n");
   // readRecipes(_drinks,_selectedIngredients);
    } 
     myRecipeList.close();

}
  // Close file
 

void loop() {
}

void readData(char * myString, int len) {
  for (int i =0 ; i < len; i++)
    myString[i] = myRecipeList.read();
}

void readIngredients(ingredient * selectedIngredients,ingredient * ingredients) {
  Serial.print("reading ingredients..");
 boolean done = false;
 ingredient * myIngred;
 numIngreds=0;
 while ( numIngreds < MAX_INGREDIENTS && myRecipeList.available()) {
    myIngred = (ingredient*)&ingredients[numIngreds];    
    readData(myIngred->name, NAME_SIZE);    
    char amnt[AMNT_SIZE];
    readData(amnt,AMNT_SIZE);
   myIngred->amount = atoi(amnt)/100.0;   
    numIngreds++;  
  }
  
  // Default to first ingredient in list (should be water)
  // Load this ingredient into all six ingredients holders
int i = 0;  
for (; i < MAX_INGREDS_PER_DRINK; i++){}
    strcpy((char*)selectedIngredients[i].name,ingredients[0].name);
}

What values are assigned to NAME_SIZE and MAX_INGREDS_PER_DRINK?

My guess is that are running out of memory. While that is rarely an issue on a PC, it IS a big deal on an Arduino with a (very) limited amount of memory.

Which Arduino are you using?

This is correct. It was a memory issue, I think. I was using a duelmilove with 30k of ram. 12k was used for the code and the structs that needed to hold the data came to about 8k. while this is only about 20k, when I switched to an arduino mega, everything works great.
Im not sure what the other 10k of memory was filled with.

sassafrassquatch: This is correct. It was a memory issue, I think. I was using a duelmilove with 30k of ram. 12k was used for the code and the structs that needed to hold the data came to about 8k. while this is only about 20k, when I switched to an arduino mega, everything works great. Im not sure what the other 10k of memory was filled with.

30k of RAM? You've confused flash and RAM. Your duelmilove has an ATmega328 which only has 2K of RAM. There is 32K of flash. Switching to the Arduino Mega means you moved to a processor with 8K of RAM (not 128K).

Looking at the complied code's total size doesn't give you any idea of how much actual RAM is being used during run time.