SD sketch won't compile with FILE *dataFile = ...

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
oldfox
 
Posts: 43
Joined: Wed Jan 23, 2013 4:18 pm

SD sketch won't compile with FILE *dataFile = ...

Post by oldfox »

With includes of <stdio.h> and <sd.h> the following won't compile:
FILE *dataFile = SD.open("MEGA20x4.dxf");

This will compile and run just fine:
File dataFile = SD.open("MEGA20x4.dxf");

Where is the problem?
The sd.h if the unmodified file supplied by AdaFruit.
Thank you.
-oldfox-

User avatar
oldfox
 
Posts: 43
Joined: Wed Jan 23, 2013 4:18 pm

Re: SD sketch won't compile with FILE *dataFile = ...

Post by oldfox »

Has anyone from "adafruit-support" read this post yet? If not, why? If so, it would only be common courtesy to acknowledge that fact, even if you don't have an answer yet. Just let the poster know what is going on. Thank you.

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: SD sketch won't compile with FILE *dataFile = ...

Post by adafruit_support_bill »

Some more detail would be helpful.
What product are you referring to?
What sketch are you trying to compile?
If it is an example sketch, post a link to the code. If it is your own sketch, post the source.

User avatar
oldfox
 
Posts: 43
Joined: Wed Jan 23, 2013 4:18 pm

Re: SD sketch won't compile with FILE *dataFile = ...

Post by oldfox »

Product is Adafruit datalogger shield for Arduino. (factory assembled)
Arduino is MEGA2560 R3.
Attached is the modified DumpFile.ino file from the SD library example.
I changed the File datafile = SD.open("datalog.txt"); to
FILE *datafile = SD.open("MEGA20x4.dxf"); because that is the file I loaded onto the SD card. I was going to use the pointer further in my own sketch but it produced a compile error at that line.
Error was as follows:
DumpFile:59: error: request for member 'read' in 'dataFile', which is of non-class type '__file*'
I'm not a programmer so I don't always understand error messages.
I also changed chip select to 10. The original example runs fine.
See attached file.
Thank you.
Attachments
DumpFile_ino.txt
Change extension to .ino to run in Arduino IDE
(1.91 KiB) Downloaded 150 times

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: SD sketch won't compile with FILE *dataFile = ...

Post by adafruit_support_bill »

I changed the File datafile = SD.open("datalog.txt"); to
FILE *datafile = SD.open("MEGA20x4.dxf"); because that is the file I loaded onto the SD card. I was going to use the pointer further in my own sketch but it produced a compile error at that line.
Changing the file name is fine. But SD.open() returns an object of type "FILE", so assigning it to FILE* is a problem.

I don't believe you need a pointer for what you want to do. If you want to access dataFile elsewhere in your sketch, declare it at file scope (i.e. before the setup() function) and just assign to it in setup as:

Code: Select all

datafile = SD.open("MEGA20x4.dxf");

User avatar
oldfox
 
Posts: 43
Joined: Wed Jan 23, 2013 4:18 pm

Re: SD sketch won't compile with FILE *dataFile = ...

Post by oldfox »

Thank you for that information. I will give it a try.
And I apologize for the previous rant. I was a little keyed up over this project.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”