Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

How to print buffer using UART as stdout

Hello all,

When I stored a string to a buffer using Uart, how to print it using same Uart? Something like below but this example using JTAG Uart.

<div class='quotetop'>QUOTE </div>

--- Quote Start ---

int main ()

{

char cStr[80];

printf("Enter a string:\n");

gets (cStr);

printf("\n\nString yang anda masukkan ialah:%s\n", cStr);

return 0;

}[/b]

--- Quote End ---

I try to do like this but failed...

<div class='quotetop'>QUOTE </div>

--- Quote Start ---

int main ()

{

char* msg = "Enter a string: &#39;t&#39;.\n";

char* msg4 = "Cipher-Text ialah:\n";

FILE* fp;

char cStr[80];

fp = fopen ("/dev/uart1","r+");

fwrite (msg, strlen (msg1), 1, fp);

gets (cStr);

fwrite (msg4, strlen (msg4), 1, fp);

fprintf(fp, "%s", cStr);

fclose(fp);

return 0;

}[/b]

--- Quote End ---

thanks in advance

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    hai ,

    i think u had a problem in using the fprintf and fwrite , use fprintf or fwrite in your program ,because fwrite writes in binary format ,but fprintf writes in human readeable format ,

    i think ur problem can be solved with this ...

    regards,

    Murugan.b