Reading Commands from SD card

I don’t speak C very well and I am running into a wall with a chunk of code that I am sure someone else has already come up with something close already.
I am working with a Teensy++, and an LCD with an SD card shield and I am using the standard sd.h library.
I am trying to read a txt file from the SD card one line at a time to a string.
I would then like to look at the first char of the string to determine how to process the remainder of the line.
For example:
File.txt:

PPicture1.bmp
TThis is text I would like to display on the screen
PPicture2.bmp
TThis is andother example of text

The desired output is sending the line data to the appropriate voids like

bmpDraw("Picture1.bmp", 0, 0);
tft.drawString(0, 0, “This is text I would like to display on the screen”, color);
bmpDraw("Picture2.bmp", 0, 0);
tft.drawString(0, 0, “This is andother example of text”, color);

My friend wrote this for me in C++ to get me started but I keep getting it to work on local machine.
The idea being get a proof of concept working before getting it to work on the arduino.

#include <fstream>
#include <iostream>


using namespace std;


char toLower(char c) {
	if((c >= 65) && (c <= 90)) {
		return (char) (c + 32);
	} else if((c >= 97) && (c <= 122)) {
		return c;
	}
	return '\0';
}


int main(int argc, char *argv[]) {
	ifstream fin("file.txt");
	
	//Maximum amount of bits being read in at one time.
	short bin = 512;
    
	char c;
	int l = 1;
	bool error;
    
	//Iterates through the file.
	while(fin.get(c)) {
		//Ignores whitespace.
		while(c == '\n') {
			fin.get(c);
			l++;
		}
		
		// Declares and reads in the line from the file.	
		char* line;
		fin.get(line, bin);
		
		//If you want case insensitive change to: switch(toLower(c));
		switch(c) {
			case 'P':
				cout<<"PICTURE"<<line<<endl;
				break;
			case 'T':
				cout<<"TEXT"<<line<<endl;
				break;
			default:
				// If we couldn't determine the letter, print out an error.
				cout<<"[!] Error on line: "<<l<<endl;
				error = true;
				break;
		}
	}
 
	if(error) {
		//Do something...
	}
	
	fin.close();
	cin.get();
	return 0;
}

Problem is I keep getting Unhandled exception: Access violation writing location.
Yet this script works:

ifstream fin("data.txt");  
string s;  
while( fin >> s ) {    
cout << "Read from file: " << s << endl;  
}

If someone could take a look and help me get this working I would be very grateful.

The desired output is sending the line data to the appropriate voids like

Psst. You misspelled functions.

Problem is I keep getting Unhandled exception: Access violation writing location.

Where? The Arduino doesn’t do exception handling.

I was trying to get this example code working in Dev-C++ before porting it to the arduino when I recieved the error. I am not married to this code but it seems close to what I want. I am just trying to put commands in a text file that can be used by different functions. Does anyone have an example of this? It seems like it should be simple enough for people that know C.

There are examples that come with the SD library. Why not use one of them as a starting point?

The issue I am having is not related to the SD lib or getting it to work on the Arduino. Basically I don't understand the how to get the string and char functions in C to do what I want. Once I figure the generic verbage out, I think the rest should fall in place. I have a VB background which is proving to be pretty useless right now.

maybe start working through Kerningham and Ritchies work about C first: - http://letrongngoc.tech.officelive.com/Documents/TheCProgrammingLanguageSecondEdition.pdf -

  • The physical book is worth buying too

If you have real experience with VB you can work through this book in a few evenings (to grasp some essentials, not all details)

It seems like you are reinventing the wheel, this is the sort of thing that bitlash does, http://bitlash.net/wiki/start It can be adapted to read off an SD card instead of the terminal.