The accursed string

Although I started programming in 1962 (FORTRAN), and have been programming ever since, I never learned C until I wanted to use Arduinos. and mostly, I've learned it incrementally, picking up new parts as needed. My impression of C, overall, is that it is a very crude language, and somehow represented a devolution from much better languages that preceded it (Pascal, Modula 2). It caught on because it was bundled with Unix, which in the early days was pretty much the only game in town.

But I'm not actually posting this to start a fight. My problem is with the concept of string in C as an array of characters. The String object has many functions devoted to its manipulation, while the string, in Arduino reference, has almost none. I use Strings almost exclusively, but every now and again I find a library that wants strings.

So at the moment I am trying to create a convert_String function which accepts a String, and outputs a string. That's easy enough in concept, but I don't know how to declare a function of type string. Do have to make it a pointer to char?

Why duplicate toCharArray()?

The String object has many functions devoted to its manipulation, while the string, in Arduino reference, has almost none.

That is nonsense. There are many, many functions that can deal with strings (NULL-terminated arrays of chars) - strcat(), strcmp(), strstr(), strtok(), to name just a few. EVERYTHING that the String class can do is done using the internal string and the string functions.

jrdoner:
The String object has many functions devoted to its manipulation, while the string, in Arduino reference, has almost none.

You should look in a different place http://www.atmel.com/webdoc/AVRLibcReferenceManual/group__avr__string.html

I have just finished converted a large sketch which was using Strings, to string. It took a long time, but using Strings I feel, is like rolling a dice, waiting for your program to glitch. There is a list of methods you could use for strings <cstring> (string.h) - C++ Reference, although not as simple as String functions and requires more work.

An sample return string function.

char* myFunction()
{  
  static char myString[] = "SomeText";  
  return myString;
}

My impression of C, overall, is that it is a very crude language, and somehow represented a devolution from much better languages that preceded it (Pascal, Modula 2). It caught on because it was bundled with Unix, which in the early days was pretty much the only game in town.

Yes, Pascal and Modula2 are clearly vastly superior to c/c++, which explains why so much of modern software development is done using Pascal and Modula2, while c/c++ have been virtually abandoned.....

Yikes....

Regards,
Ray L.

The Arduino Language Reference page is only a starting point. It's not a comprehensive C++ manual.

Alright. As I said before, I backed into the C language, and what I didn't see on the Arduino reference page, I assumed was not implemented for Arduino. I'll go look up the string functions. They'll probably greatly improve my attitude toward strings.

Thanks, fellas.

jrdoner:
Alright. As I said before, I backed into the C language, and what I didn't see on the Arduino reference page, I assumed was not implemented for Arduino. I'll go look up the string functions. They'll probably greatly improve my attitude toward strings.

Thanks, fellas.

yes, meanwhile warm up your punch card reader to start your next C++ program!

:wink:

BulldogLowell:
yes, meanwhile warm up your punch card reader to start your next C++ program!

:wink:

Punch cards? Paper tape rules!