In various situations it might be useful to have means to find out which sketch was uploaded to an Arduino (especially if you own more than one).
On March 1st, in IDE 1.6.0 is now available for download - Installation & Troubleshooting - Arduino Forum
ShapeShifter showed the usage of the pre-defined macro FILE giving the file name of the sketch.
When I updated to 1.6.6 recently, I was surprised to see the macro now returns the complete path name preceding the file name which is not what I wanted.
It is easy to strip the file name using the String class but for some reasons I usually try to avoid the usage of this class.
Collecting all my knowledge about addresses and pointers I managed to extract the file name but surely it can be done more efficiently.
void setup() {
Serial.begin(9600);
Serial.println(__FILE__);
char s[] = __FILE__;
byte b = sizeof(s);
while ( (b > 0) && (s[b] != '\\')) b--;
char *u = &s[++b];
Serial.println(u);
}
void loop() {
// put your main code here, to run repeatedly:
}