Question about the String object

hi just a quick question, I'm kinda new at this so bare with me:

i built a library and the one of the parameter's is a String. However the compiler treats it like a char, even saying char in the error code. Although its defined as a String, and the rest of the code dealing with the parameter 'name' says String.

These are the errors:

checkname_on_lcd:9: error: invalid conversion from 'const char*' to 'char'
checkname_on_lcd:9: error: initializing argument 1 of 'Alarm::Alarm(char, char, char, int, int, int, int, int, int, int)'

Is it possible to use strings in a class? i know you can in the program itself as it works. I tried that before building the class. Please and thanks for your time and advice. Also if you treat the name string parameter like a char, the program works, as it obvs thinks it is a char. I have uploaded the earliest code revision i have where i noticed the error.
Srry my serial monitor doesnt work so i included the code for my lcd display.

computer specs
windows 7 64 bit updated
using arduino version 1.01

checkname_on_lcd.ino (598 Bytes)

Alarm.cpp (765 Bytes)

Alarm.h (1.41 KB)

Alarm Alarm1("towak", 'crazyrun', 'xxxxville', 0, 1, 10, 1990, 6, 9, 0);

Strings have to be in double quotes. Your second two are in single quotes.

You should avoid using the String class as it is incredibly huge and bulky.

You can do everything using char* that you can with String - it just takes a little more thinking about.

Nick Gammon: thx, yeah when I realized I had a problem with the string class, I switched the other 2 to chars so i could work with one controlled string variable. This would allow me to see the differences between the char and the string, as i am very new, and this would be my first project.

majenko: thank you, i will look into char* although i am not familiar with it. I was just trying to use the string class because that is what i'm most familiar with. btw can you use the char* to make a large sentence with, cause i will run into that problem for description and location.

Thanks to everyone for all the help and advice

can you use the char* to make a large sentence with

You can fill it with as much data as you allow for:

char myString[128]; // Allocate 128 bytes of data for this string

snprintf(myString,127,"I asked the shop keeper for %d apples, but he only gave me %d.",apples,apples-1);

would end up with myString containing "I asked the shop keeper for 5 apples, but he only gave me 4." if apples was equal to 5.

The "k" of "keeper" is myString[17], as it is the 18th character, and C arrays count from 0 not 1.

You can create a pointer to a string with the * operator:

char *myPtr;

myPtr = myString;
myPtr += 17;
Serial.println(*myPtr);

would print 'k' to the serial device. Again, character 18. myPtr points to the first character of the string. Add 17 to it and you now point to (1+17) the 18th character, which is the k of keeper.

There are many things you can do using pointers like this.

A char * string is terminated with character 0 (not the ASCII character "0", but ASCII code 0). Make sure your strings are terminated with that character or you will start getting garbage. Most operations will put that 0 in there for you automatically, but there are a few (such as strncpy) that won't, so you need to be aware of it.

One trick is to split a string into two separate strings by simply creating a pointer to the first character of the second half of the string, and replacing the previous character (or inserting a new one) with character 0 to terminate the first half of the string.