How to print '\n' instead of a newline?

前端 未结 11 599
南方客
南方客 2020-12-11 04:34

I am writing a program that uses prints a hex dump of its input. However, I\'m running into problems when newlines, tabs, etc are passed in and destroying my output formatti

11条回答
  •  长情又很酷
    2020-12-11 05:10

    There are three solutions for this question:

    Solution 1: Every Symbol, Number, Alphabet has it's own ASCII value. The ASCII value of '\' as 92 and 'n' as 110. The immediate values(Numbers (ASCII)) are stored onto two integer variables. While printing, the format specifier %c (Character), is used.

    void main() { 
        int i=92, j=110; 
        clrscr(); 
        printf("%c%c", i, j);
        getch();
    }
    

    Try it out in your C programming software...

    Solution 2:

    The programs works. But I think this one isn't fair... At the output screen, type the input as \n... you will get another \n..

    void main() {
      char a[10];
      gets(a);
      printf("\n\n\n\n");
      puts(a);
      getch(); 
    }
    

    Try out the programs

    Solution 3: Already said above use \n

提交回复
热议问题