![]() |
| | #1 |
| Registered User Join Date: Feb 2009
Posts: 278
| converting a char to a "string" 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!");
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? |
| Bladactania is offline | |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| You either need a separate function to send one character, or make it into a string (an array of 2 characters, with the second character a zero). -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #3 |
| Registered User Join Date: Feb 2009
Posts: 278
| Doesn't my second attempt make it into a string? The sscanf? |
| Bladactania is offline | |
| | #4 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| Maybe you wanted to use sprintf instead of sscanf? That would make more sense there...the sscanf will be reading from Temp into ManualCommand (why?). Then you send Temp, which has no defined content.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS Last edited by MK27; 04-20-2009 at 01:03 PM. |
| MK27 is offline | |
| | #5 |
| Registered User Join Date: Feb 2009
Posts: 278
| Oh my good Lord! That's what I get for reading forums before coding! I had been reading a thread about sscanf. Thanks |
| Bladactania is offline | |
![]() |
| Tags |
| char, malloc, sscanf, string |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Selecting bits with Unions.... Not working; please help!! | dan56965 | C Programming | 12 | 08-11-2008 11:02 PM |
| Obtaining source & destination IP,details of ICMP Header & each of field of it ??? | cromologic | Networking/Device Communication | 1 | 04-29-2006 02:49 PM |
| program sections were working fine until it came to putting it together | shoobsie | C Programming | 6 | 06-30-2005 08:03 AM |
| Program Crashing | Pressure | C Programming | 3 | 04-18-2005 10:28 PM |
| comparing fields in a text file | darfader | C Programming | 9 | 08-22-2003 08:21 AM |