How to get one character from __FILE__

Hi, I use the letters "a" through "z" for daily builds of a project.

Save-As "ford-04-09a.ino" for the first version today. Save-As "ford-04-09c.ino" for the third version today.

I'd like to display just the version indicator character in an LCD, as in "lcd.print(ver);" Where "ver" is the "a" or "c" or whatever.

How do I extract just that indicator character?

I have been messing with "charAt" and "ver.length(..." and getting nowhere fast.

A lifetime of Pascal has me struggling with c++. :)

Thanks

__FILE__[10]

[quote author=Coding Badly link=msg=3213486 date=1491768990] __FILE__[10] [/quote]

If only it were that easy, I would not have wasted people's time by asking. It seems hard to get good help these days.

If you check the "FILE" C++ Help, you will see that it produces a String that includes the entire file-Path.

Also, IF the file naming convention use for another project doesn't have the exact same structure as this project then "10" could and would be anything.

Old Army saying, "Lead, Follow or get out of the way." The "10" seems to fit in there somewhere.

If you check the "FILE" C++ Help, you will see that it produces a String that includes the entire file-Path.

It most certainly does NOT!

It produces a string literal. You can copy that string literal into a char array, append a NULL, and then parse the string.

 const char * fileVersion = (strrchr(__FILE__,'-') + 1);

If only it were that easy...

It is.

__FILE__[sizeof(__FILE__)-5]

[quote author=Coding Badly date=1491794621 link=msg=3213815]

__FILE__[sizeof(__FILE__)-5]

[/quote] That will give the '.' if the file suffix is ".ino". I think you forgot to count the '\0' at the end.

This will give the character at the place of X and is easy to update if the file suffix is changed.

__FILE__[sizeof(__FILE__)-sizeof("X.ino")]

oqibidipo: I think you forgot to count the '\0' at the end.

Nope. I assumed, given @SalineSolution's condescending attitude, he would not bother with anything else I wrote so I did not bother putting any thought into my post beyond making it understandable.

I also assumed anyone who had an interest, like you, would easily find any mistakes I made.

This will give the character at the place of X and is easy to update if the file suffix is changed.

Nice.

PaulS:
It most certainly does NOT!

Ummmm

[quote author=Coding Badly link=msg=3213992 date=1491810247] I assumed, given @SalineSolution's condescending attitude[/quote]

Ummm, it was Reciprocal condescension :) See the pic for PaulS and why the "10" would rarely if ever apply.

Can we all stay calm now. Breath-in, breath-out, breath-in...

@oqibidipo : Thanks, that works a treat.

SalineSolution: Ummm, it was Reciprocal condescension :)

You see such things in that very short snippet of code?

you will see that it produces a String that includes the entire file-Path

It most certainly does NOT!

I believe this is a complaint about "String" (which would be a C++ String data type), rather than about the presence of the path in the C-style null-terminated character array literal...

__FILE__[sizeof(__FILE__)-sizeof("X.ino")]

Lovely! Note that this all gets evaluated at compile-time to a simple char value. (unlike the call to strchr(), probably.)

Due to the change from FILE containing just the filename, I find I need to re-acquire just the filename for versioning purposes. (I display the filename in a 2x16 display). Any thoughts on how to do this without implementing sed or perl would be welcomed!

char tmp[] = __FILE__;
char *ptmp;
  // Point to last char in string
  ptmp = &tmp[strlen(tmp)-1];

  // Go backwards through the string until we either
  // find a backslash or reach the beginning of the string
  while((ptmp > tmp) && (*ptmp != '\\'))ptmp--;

  // If we found a backslash move forward one char to the
  // start of the filename 
  if(*ptmp == '\\')ptmp++;

  Serial.print("Start ");
  Serial.println(ptmp);

Pete

Awesome!

Thanks for the quick response!

And perhaps even more amazing, a straight copy/past works exactly as advertised!

Actually I was hoping someone would provide a macro like FILE_LESS_PATH but I'll take this to the bank.

Jay