T
ttkingdom
I have here 1 elementary piece of code, which produce different result
in DOS and Cygwin. I'm puzzled and don't know what caused this.
This program counts the number of characters, spaces, lines, and tabs.
It is compiled with gcc
#include <stdio.h>
int main ()
{
double countline = 1, countchar = 0, counttab = 0, countspace = 0;
int c;
printf("Please type in anything, end with EOF (CTRL + D or Z): \n");
while ((c = getchar()) != EOF)
{
if (c == '\n') { ++countline; }
else if (c == ' ') { ++countspace; }
else if (c == '\t') { ++counttab; }
else { ++countchar; }
}
printf("\nYou have typed in %.0f char(s), %.0f space(s), %.0f tab(s),
%.0f line(s).",
countchar, countspace, counttab, countline);
return 0;
}
This program ends when input is EOF, which is CTRL + Z in DOS, CTRL +
D in Cygwin (somewhere on the internet says so )
The problems are:
1/ It ends well in DOS with a CTRL + Z, but in Cygwin it needs a CTRL
+ D and an ENTER.
2/ In DOS it count the number of space and tab incorrectly. Try enter
5 spaces and 3 tabs. In Cygwin it counts correctly.
Please anyone explain to me what causes these discrepancies.
in DOS and Cygwin. I'm puzzled and don't know what caused this.
This program counts the number of characters, spaces, lines, and tabs.
It is compiled with gcc
#include <stdio.h>
int main ()
{
double countline = 1, countchar = 0, counttab = 0, countspace = 0;
int c;
printf("Please type in anything, end with EOF (CTRL + D or Z): \n");
while ((c = getchar()) != EOF)
{
if (c == '\n') { ++countline; }
else if (c == ' ') { ++countspace; }
else if (c == '\t') { ++counttab; }
else { ++countchar; }
}
printf("\nYou have typed in %.0f char(s), %.0f space(s), %.0f tab(s),
%.0f line(s).",
countchar, countspace, counttab, countline);
return 0;
}
This program ends when input is EOF, which is CTRL + Z in DOS, CTRL +
D in Cygwin (somewhere on the internet says so )
The problems are:
1/ It ends well in DOS with a CTRL + Z, but in Cygwin it needs a CTRL
+ D and an ENTER.
2/ In DOS it count the number of space and tab incorrectly. Try enter
5 spaces and 3 tabs. In Cygwin it counts correctly.
Please anyone explain to me what causes these discrepancies.