Thread: Different outptus from different compilers

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    12

    Different outptus from different compilers

    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,

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    What input data are you using? It seems to work fine under gcc 2.95.3 in Linux (after removing the "press any key" message and the getch() call):
    itsme@dreams:~/C$ ./count
    iwauiovmnaOIFU29837849naonbhaiosfdjakls<EOF>
    A = 5 B = 1 D = 1 F = 2 H = 1 I = 4 J = 1 K = 1 L = 1 M = 1 N = 3 O = 4 S = 2 U = 2 V = 1 W = 1 itsme@dreams:~/C$
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    12
    I tried with multiple and different input sets, the outputs of all started out with R's frequency, if present.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    I'm guessing that since you don't print any newlines that the output simply wraps over itself and hence "appears" to only start at certain letters.

    Perhaps
    Code:
    printf(" %c = %d\n", i + 'A' , iAlphabets[i]);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    12
    No. That couldn't be the case as i used clrscr() in TC, but deleted the line for portability reasons.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    And you're sure? What happens if you add a newline after every five outputs?

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Builder Comparison
    By ryanlcs in forum Tech Board
    Replies: 14
    Last Post: 08-20-2006, 09:56 AM
  2. Is It Possible To Install Multiple Compilers?
    By mishna_toreh in forum C Programming
    Replies: 3
    Last Post: 05-13-2005, 07:32 AM
  3. Compilers for Windows
    By LegendsEnd in forum Windows Programming
    Replies: 2
    Last Post: 03-26-2004, 08:03 AM
  4. scientific calculators with compilers?
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-06-2003, 08:29 PM
  5. Compilers, Compilers, Compilers
    By Stan100 in forum C++ Programming
    Replies: 11
    Last Post: 11-08-2002, 04:21 PM