I am working on programming an Arduino board in C, and thus cannot print unless I do serial communication to an external terminal window.
Because of this I have developed a printAll method:
void printAll(char * str) {
int i;
for(i = 0; str[i] != 0x00; i++) {
PSerial_write('0', str[i]);
}
}
I also have a variable:
char input[12];
input[0] = 'h';
input[1] = 'e';
input[2] = 'l';
input[3] = 'p';
What I would like to do is pass this array into the printAll method (but the printAll method takes a char*).
I have tried to do:
printAll(&input[0]);
But nothing gets printed! But when I step through and print each character of the input array I get:
help<0><0><0><0><0><0><0><0>
Can anyone explain why this is not working? Thanks!
***NOTE: the printAll method works perfectly fine when used like so:
printAll("Hello World!");
Overall my code looks like this:
char input[12];
int main(void) {
start();
}
void start() {
while(1) {
printAll("Please enter in a command!\r");
printAll("Please type 'help' for instructions!\r");
char input[12];
readInput(input);
printAll("Trying to print the char array stuff....\r");
printAll(input);
if (input == "help") printHelp();
else if (input == "set") {
if (setStatus) printSet();
else printAll("Controller not authorized to print.\n");
}
else if (input == "set on") setStatus = true;
else if (input == "set off") setStatus = false;
else if (input == "set hex=on") hexFormat = true;
else if (input == "set hex=off") hexFormat = false;
else if (input == "set tlow") tlow = getNumber(input);
else if (input == "set thigh") thigh = getNumber(input);
else if (input == "set period") period = getNumber(input);
x_yield();
}
}
void readInput() {
char c = PSerial_read('0'); //reads character from user
while (c != '\r') {
//while the character isnt 'enter'
input[currIndex] = c;
c = PSerial_read('0');
currIndex++;
}
int y;
for(y = 0; y < 12; y++) {
PSerial_write('0', input[y]);
//go through input and print each character
}
PSerial_write('0', '\r');
//add new line to print log
currIndex = 0; //reset for next input (overwrites current stuff)
}
Right now no matter what I input, it just asks for more input, and never prints the array out after the input method returns.