A warm hello to all the contributors to this forum,
To be precise, two different compilers -
DevCpp ver 4.9.9.2 &
Tc by Borland ver 3.0
have given me two different outputs for the same program. TC excelled because it's output was what i intended it
to be, whereas DevCpp didn't produce the intended output.
The program -
Code:
/*
Assumptions - All alphabets are regarded irrespective of their cases. 'A' is considered same
as 'a'. Numbers having multiple digits are looked as group of single digits. For example, 12
is considered as digit 1 and digit 2. Absence of a histogram for any character should mean the
absence of that character. All the other special characters except those mentioned above are
not included.
*/
#include <stdio.h>
#define SUCCESS 0
#define ERROR -1
#define ALPHABETS 26 /* a - z, case - irrelevant */
#define DIGITS 10 /* 12 means digit 1 and digit 2 */
#define NEWLINE 2 /* indices for the whitespaces */
#define TAB 1
#define SPACE 0
#define WHITESPACES 3
int main(void)
{
/* Variable declaration and definitions */
int iExitCode = SUCCESS,
iInput = 0,
iAlphabets[ALPHABETS] = { 0 },
iNumbers[DIGITS] = { 0 },
iWhiteSpaces[WHITESPACES] = { 0 },
/* iGap = 0, */
i = 0;
/* Take input and fill the arrays with information */
while((iInput = getchar()) != EOF)
{
if(iInput == ' ')
iWhiteSpaces[SPACE] += 1;
else if(iInput == '\t')
iWhiteSpaces[TAB] += 1;
else if(iInput == '\n')
iWhiteSpaces[NEWLINE] += 1;
else if(iInput >= 'A' && iInput <= 'Z')
iAlphabets[iInput - 'A'] += 1;
else if(iInput >= 'a' && iInput <= 'z')
iAlphabets[iInput - 'a'] += 1;
else if(iInput >= '0' && iInput <= '9')
iNumbers[iInput - '0'] += 1;
else ;
}
for(i = 0 ; i < ALPHABETS ; i++)
if(iAlphabets[i] != 0)
printf(" %c = %d ", i + 'A' , iAlphabets[i]);
/* Exit code */
printf("\n Press any key to exit...");
getch();
return iExitCode;
}
The output -
By The DevCpp (Wrong one) :-
Starts by O, skipping A - N.... even if A has some entries.
By TC :-
Runs as intended, starts with A if A has any entries, and moves methodically
Friends, i don't know what is causing the DevCpp to output the kind that it is churning...
I am at my wit's end, and any help will be appreciated.
Thank u all in advance,