Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12604 Discussions

How to print buffer using UART as stdout

Altera_Forum
Honored Contributor II
1,416 Views

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
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
493 Views

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
0 Kudos
Reply