Extract data from SDcard into arrays. Please Help

I've been working on a small project for my university. I am having issues being able to extract data from a text file.

text file looks like:
8
0
9
0
10
0
11

and the extracted file looks like with char
8

0

9

0

1
0

0

1
1

What it looks like with int
48
13
10
48
13
10
49

I'm not sure how to fix it. I'v tried using string, float, int, char. Each gives me a odd answer, that is, for float it was giving me 48, 53, etc...

my current code is
#include <SD.h>

char filename[20];
File dataFile;
int i;
char data[200];

void setup()
{
Serial.begin(9600);
Serial.println("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(4))
{
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");

File dataFile = SD.open("Test.txt");
if(dataFile)
{
Serial.println("Reading Text File");
while(dataFile.available())
{
for (i=0; i<=200; i++)
{
data[ i ] = dataFile.read();
Serial.println(data[ i ]);
}
Serial.println("File Downloaded");
dataFile.close();
}
}
else
{
Serial.println("File does not exist");
}
dataFile.close();
}

void loop()
{
int l=0;
snprintf(filename, sizeof(filename), "data%03d.txt", l); // includes a three-digit sequence number in the file name
while(SD.exists(filename))
{
l++;
snprintf(filename, sizeof(filename), "data%03d.txt", l);
}

Serial.println("New Txt File Created");
File dataFile = SD.open(filename,FILE_WRITE);
for (i=0; i<=100; i++)
{
dataFile.println(data[ i ]);
}
Serial.println("Data Uploaded to new text file");
dataFile.close();

delay(100000);
return;
}

It looks like it is somewhere here... data[ i ] = int(dataFile.read()); (i dimmed it a char above...)

Please Help

I don't understand what you are trying to do. Why you don't simply remove the SD card from your shield and put it in your PC and open it with excel (or whatever program you want).

I am attempting to make an array using the data from the txt file. I have a working program that creates the text file with that correct data. I am then using the txt and running an analysis on MATlab. I've upgraded to the mega microcontroller, giving me more space to run the analysis directly in the arduino.

My next task is to be able to take the txt and be able to import it as an array. Run the analysis then export it into another txt file.

test.txt
0
1 9
54
3
9

should be imported into an array of

a(x)=data such that a(0)=0, a(1)=19, a(2)=54 and so on...

my apologies if it is confusing.

I think I understand what you want. One question: you know the length of the first file (the number of values that you have in it)?

20,000 -100,000Hz with intervals of 100. so 800 is what I need.

I'm not sure what my test.txt currently has however...

the txt I am going to be using has two values, the freq and the voltage(ex: 20000, -1)

The main problem that you have is that when you do dataFile.read(); you read one character of the file and not the entire value in that line:

So, you need to read char by char until the character '\n' (that marks the end of the line) and then covert that set of characters to a integer value.

I don't know what are your level of C and if what I write makes sense to you.

ok, I totally get it...

I'll work on it. Thanks!

although I have no idea how...

The idea is to do something like what is done here, but using dataFile.read() instead of Serial.read().

I don't think i'll be able to sleep tonight. Cheers Undergrad nights! I'm understanding it. lets hope i get it working. :fearful:

thank you again for the help, and so quick too...

p.s in Miami we have "Colada". XD