I have a function that accepts a c-string (a char *). The function transmits each character of the string via the serial port. Inside the function, the strlen function is used to determine how many characters to transmit. The function works well when I do...
However, I'd like to send a single character that I get from a variable...Code:void Transmit_String(char *Log_String) { int Line_Ready = 0; int Length = strlen(Log_String); int x; for (x = 0; x < Length; x++) { // Check to make sure port is ready to send while (Line_Ready == 0) { Line_Ready = inportb(COM2_LINE_STATUS) & 0x20; } Line_Ready = 0; // Send next byte outportb(COM2_BUFFERS, Log_String[x]); } } // Example Call Transmit_String("Hello World!");
I always seem to get random junk though instead of the expected character.Code:char Manual_Command = '~'; //I initially tried Transmit_String(&Manual_Command); //Then... char *Temp = (char *) malloc(sizeof(char) * 5); sscanf(Temp, "%c", &Manual_Command); Transmit_String(Temp);
What am I doing wrong?



LinkBack URL
About LinkBacks



