I / O redirection

#include<stdio.h>
#include<stdlib.h>

int main()
{
   int i;
   for(i=1; i<=255; i++)
   {
       printf("%d %c\n",i,i);
   }
}

Hi, I am working on exiting i / o forwarding and I am stuck in the output of the ascii table from the command line. I have done it.

C:\New folder\practice> main.exe > temp.txt

C:\New folder\practice> type temp.txt

and after pressing input (after type temp.txt) it displays only the first 26 numbers. My question is why?

Also can someone explain to me how easy it is to copy the code to a text file using redirection. I know how to do this using FILE I / O.

+4
source share
2 answers

Since you are using MS-DOS ... er MS WinDOS, and there ASCII number 26 / ^ Z is the sign of the end of the text file.

, CP/M 1970- , , . , type , more ... ( ).

.

+6

. 0x10 \n , \r\n Windows.

- :

#include<stdio.h>
#include<stdlib.h>

int main()
{
   int i;
   FILE *fd = fopen("temp.txt", "wb");
   if (NULL == fd) {
      perror("Error opening file");
      return 1;
   }
   for(i=1; i<=255; i++)
   {
       fprintf(fd, "%d %c\n",i,i);
   }
   fclose(fd);
   return 0;
}

, , , SUB (Ctrl Z code 0x1A), ...

+2
source

Source: https://habr.com/ru/post/1692351/


All Articles