String Variables used as pointers

Hello,

I dont undrestand why I can not use as standard C as alwyas the variable in many of ardwuino functions like:

String errorMsg; // a string for error messages

then in the setup() or the Loop ()
errorMsg = " Error Condition detected... ";
Serial.println(errorMsg);
or
String fileName;
fileName = "CONFIG.INI";
configFile = SD.open(fileName, FILE_WRITE);

This examples doe NOT give any Compiler Error ...
BUT when UPLOADING is hunging the Serial Port giving Timeout, never ending the Upload ????

I have to specifically set the funtions like:
configFile = SD.open("CONFIG.INI", FILE_WRITE);
to be able to work ..

Why ?

Thanks
Adrian

SD.open takes a string and not a String.

adrarduino:
I dont undrestand why I can not use as standard C

As Delta_G points out, the "String" object is not standard C. It is specific to the Arduino library.

Standard C strings are character arrays.

BUT when UPLOADING is hunging the Serial Port giving Timeout, never ending the Upload ????

I note your use of superfluous question marks.
Does your sketch (which you didn't post) contain, by any chance, superfluous exclamation marks?

adrarduino:
BUT when UPLOADING is hunging the Serial Port giving Timeout, never ending the Upload ???

Can you post a complete sketch which demonstrates the problem? Preferably a minimal one.

If you have a (capital-S) String object and need to use it in a place where (lowercase-s) string (i.e. a C-style null-terminated char array) is expected, you can use the c_str() method:

SD.open(fileName.c_str(), FILE_WRITE);

As your thread title already suggests, pointers are the easiest solution.

char* msg;

if ( ok ) msg = " OK ";
else      msg = " An error message";
Serial.println(msg);

char* fileName = "DATALOG.TXT";
SD.open(fileName, FILE_WRITE);

If you want to do it right, you should define it as

[b]const[/b] char *

and in the second sample

char fileName[] = "DATALOG1.TXT";

is fine as well.

(Here, you might even dynamically modify the fileName to open, by e.g.

   fileName[7] = '2' ;

Much easier than with String objects.
)

Thanks a lot I forgot the Capital S in String is a different Function from standard C.
That solved my problem.

THKS