Pass char to char *

I'm trying to get the value from "char c;" and send it through sms which giving me a problem invalid conversion from 'char' to 'char*, i would like to put char c; to sms.SendSMS(number,c) // the this is the orginal sms.SendSMS(number,"you text").

#define ADMIN "92XXXXXXX"
char c;

if(strstr(message, "A"))   //condition if it receive an "A" message from my phone
               {
 Wire.beginTransmission(5);
                    Wire.requestFrom(5,5);     //"5" to communicate to other ard, "5" length of bytes

                     while(Wire.available())
                     {
                  c =Wire.read();   //reading the value, and display to Serial or LCD.
                     
                 }
                   Serial.print(c);                   //from c=Wire.read(); i can get the value of what i need  ex. 45670,  and display to LCD and serial which is ok. 
                  sprintf(buf,"%lu",c); //just my experimentation...... i know this code is wrong...
               
                   sms.SendSMS(number,c);     // this is my problem, it won't compile and displaying invalid conversion from 'char' to 'char*' sms.SendSMS(number, "String code here") i know that this should be string but i'm at lost and confused.
             delay(5000);      
               }
        }

the sms.SendSMS(number,"your text"),
i would like to put like this sms.SendSMS(number,c) the char c holds the value ex. 34526 and then send. but im getting error.

the char c holds the value ex. 34526

Nonsense. A char variable holds ONE character. The value can be in the range -128 to 127.

                     while(Wire.available())
                     {
                  c =Wire.read();   //reading the value, and display to Serial or LCD.
                     
                 }

So, what is going to be in c when this loop is done? Only the last character sent. Why do you want to then send the last character as a text message?

Makes no sense to me.

thank you for the reply, yes as what i've read char can hold only one.

but in this code, it can display to LCD a "12345" or 23455 depending on the random generate number from the SLAVE (I2C) and it will stand as a password, send back to me in order for me to know. sorry for the bad logic.

when i send a message "A" the arduino will response to my message and send back a "Random number composing of 5 bytes" which will be my password.

while(Wire.available())
{
c =Wire.read(); //it can display the whole value at LCD and SERIAL MONITOR that generated from the other arduino(Slave) ex.42345.
}

How can i store the whole value that the char c get and send it, sms.SendSMS(number,c);
like value = c; then sms.SendSMS(number,value);

im really sorry for the bad description. im not really good in coding logic and still not really familiar with C, just trying my best to accomplish my project.. :frowning:

since the char c; can get the value and display it whole to LCD and Serial monitor ex. 55523 with
c =Wire.read

while(Wire.available())
                     {
                  c =Wire.read();   //reading the value, and display to Serial or LCD.
                     
                 }
lcd.print(c);

                   Serial.print(c);

i can't change the char c to char *c, i would get error and if i change the whole c to *c, it will compile but it would only display one character.

but in this code, it can display to LCD a "12345" or 23455

No, it can not. The sooner you understand that, the sooner you can make progress.

You may be able to receive, and send to the LCD, several different values, storing them ONE AT A TIME in c. You can NOT use a char to hold multiple characters.

You CAN use a char ARRAY.

Good thing i coded this one in the morning and just barely remember.

int i=0;
char myBigArray[128];
char numbers[20]={};

  while(Wire.available())
                     {
                  numbers[i]=Wire.read();
                  i++;
                 }
char str[5]= ".txt";
                 strcat(myBigArray, numbers);
                 strcat(myBigArray, str);
                 Serial.print(myBigArray);
 sms.SendSMS(number,myBigArray);

now, it can receive and reply without problem. thanks for the guide sir PaulS
i still have lots of problem to ask. :smiley:

If you get your program source code to compile, use the format option (Ctrl-T) in the IDE to reformat your code before you post it. That will make it easier for us to read your code.

got it sir econjack.

there is still a problem
when it and send sms twice, it will copy the previous text then create another text that makes it double output.

first reply is this. //no problem
ex. Sucess 1234.txt

when i text again, this is the reply. //this is the problem
ex. Success 1234.txtSucess 1234.txt

if i request for the 3rd time,
ex.Sucess 1234.txtSuccess 1234.txtSucess 123.txt

how can i return it to null so that when it reply again it won't copy the previous text.

int i=0;
char myBigArray[128];
char numbers[20]={
};
void setup()
{
}
void loop()
{

while(Wire.available())
{
  numbers[i]=Wire.read();
  i++;
}
char str[5]= ".txt";
strcat(myBigArray, numbers);
strcat(myBigArray, str);
Serial.print(myBigArray);
sms.SendSMS(number,myBigArray);     //sending sms.
}

Do you know what strcat() does? If not, research it.

When you do, you'll see the answer to your question.

mind if you can add or modify. tried return but it won't compile.

You constantly add to the end of "myBigArray". I wouldn't use strcat, but sprintf. If you insist on using strcat, then you have to "reset" the array after printing

myBigArray[0] = '\0';

I'm not insisting to use the strcat, it's just that this is what i found testing and works, if you have another suggestion, i would be very glad.

the reason i use strcat is that sms.SendSMS is in char string

sms.SendSMS(number,"your text");

so i used strcat in order accept it.
sms.SendSMS(number,strcat);

but the problem is that it won't return 0 after execution.
can you provide more code detail sir guix.

guix:
If you insist on using strcat, then you have to "reset" the array after printing

myBigArray[0] = '\0';

what code will reset strcat? im clueless from searching and reading examples.

You don't reset strcat, but your char array, so the next time you write to it, it's empty :stuck_out_tongue:

strcat(myBigArray, numbers);
strcat(myBigArray, str);
Serial.print(myBigArray);
sms.SendSMS(number,myBigArray);
myBigArray[0] = '\0'; // reset array for next time

Or, using sprintf:

sprintf( myBigArray, "%s%s", numbers, str );
Serial.print(myBigArray);
sms.SendSMS(number,myBigArray);

hehe, i though of replacing

char myBigArray[128];

to

char myBigArray[0] = '\0';

silly, and also i have sprintf and need to be null.

you hit two birds with one stone. thanks sir guix and paulS