File name character length.

i have googled this and maybe im just not googling the right thing but how would i get the number of characters in the file name from entry.name() from the default arduino SD card library. i tried

CharS = sizeof(entry.name());

no dice.

other suggestions... i am totally at fault here btw because i cannot find the variable type that is entry.name(), im not sure if its an array or a char* or a string , which is probably more than half of my problem.

TY in ADVANCE

  1. use strlen()

  2. use a loop to count the number of chars. The string is terminated by a null char.

Mark

you mean length() in arduino, googled strlen() for arduino and length comes up and you cant use length with entry.name() error comes back no such method.

int fig; char* sName=""; sName = entry.name(); fig = sName.length();

Arduino: 1.8.1 (Linux), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

WARNING: Category 'Language' in library ArduinoStreaming is not valid. Setting to 'Uncategorized'
WARNING: Category '' in library UIPEthernet is not valid. Setting to 'Uncategorized'
/home/tjohnson/sketchbook/Analog_320x240/Analog_320x240.ino: In function 'void printDirectoryTFT(SDLib::File, int, bool)':
Analog_320x240:708: error: request for member 'length' in 'sName', which is of non-class type 'char*'
       fig = sName.length();
                   ^
exit status 1
request for member 'length' in 'sName', which is of non-class type 'char*'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Look at the difference between string and String.

Mark

If i say strlen I bloody well mean strlen not anything else!

M

Serial.print(String(strlen(entry.name())));

... was that so hard? appreciate the point in the right direction though... now just have to make it an integer... ive only wasted 3 hours on this...

int fig;
String inS = "";

      inS = String(strlen(entry.name()));
      fig = inS.toInt();
      Serial.println(fig);

tada i fixed it...

Of for f***s sake

Serial.print(strlen(entry.name()));

strlen returns the length of the string what else could it be bit an int!

Mark

Sometimes you just read a post and pause for à minute and start wondering what convoluted thought process can get someone to

int fig;
String inS = "";

      inS = String(strlen(entry.name()));
      fig = inS.toInt();
      Serial.println(fig);

And then if this is how it should be why not create another String with the result of toInt() and start again...

Why would anyone think that way?

Beyond me

PS: not picking on you specifically tbillion - just amazed at how human brain fails sometimes ...

He's been String-ified or maybe he was just strung out .

Mark

look yall i never said i was the master arduino code guru of all time .. actually i came and asked for help... but if we are gonna troll and not help people then strings eat strings containing ints, i just need it to work.. always open to LEARN THE RIGHT WAY to do something from folks like you who are... FARADAY MEMBERS, js...

So I guess you now changed it to be simply

int length = strlen(entry.name());

I think you got the help, right as answer #1

I'd be curious to know how you came to the idea of putting the result of strlen into a string to then extract it again as an int?

That was my interrogation

J-M-L: I think you got the help, right as answer #1

I'd be curious to know how you came to the idea of putting the result of strlen into a string to then extract it again as an int?

That was my interrogation

er i was told to google, when i did i came across it as it was, when it worked i did not question why... yes i corrected it in my code much appreciation for the help all ...