1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Program won't execute

Discussion in 'C' started by usama_muneeb, Mar 19, 2008.

  1. usama_muneeb

    usama_muneeb Banned

    Joined:
    Mar 7, 2008
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    0
    I am using the Stephen G. Kochan C textbook. A sample program is troublng with executing. Here's the code.

    Code:
    #include <stdio.h>
    
    int main () {
    	int ratingCounters[11], i, responce;
    
    	for ( i = 1; i <= 20; ++i ) 
    		ratingCounters[i] = 0;
    
    	printf("Enter your responses\n");
    
    	for ( i = 1; i <= 20; ++i ) {
    		scanf("%i", &responce);
    
    		if ( responce < 1 || responce > 10 )
    			printf("Bad responce: %i\n", responce);
    		else
    			++ratingCounters[responce];
    	}
    
    	printf("\n\nRating    Number of Responces\n");
    	printf("------ -------------------\n");
    
    	for ( i = 1; i <= 10; ++i )
    		printf("%4i%14i\n", i, ratingCounters[i]);
    
    	return 0;
    }
    I am sick of the blinking cursor on xTerminal.
     
  2. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    This is output layout. Correct only . What you want?

    Code:
    asadulla ~/test> g++ temp7.cpp
    execution gcc-3.3.1/g++ (gprs/pcusa_passport_sas)
    asadulla ~/test> ./a.out
    Enter your responses
    10
    20
    Bad responce: 20
    30
    Bad responce: 30
    40
    Bad responce: 40
    50
    Bad responce: 50
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Bad responce: 11
    1
    2
    3
    4
    
    
    Rating        Number of Responces
    ------      -------------------
       1             2
       2             2
       3             2
       4             2
       5             1
       6             1
       7             1
       8             1
       9             1
      10             2
    
    
     
  3. usama_muneeb

    usama_muneeb Banned

    Joined:
    Mar 7, 2008
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    0
    This is meant to be a C and not a C++ program. I am using GCC. But stdio.h is C library, not C++, wonder how you compiled it under G++.
     
  4. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    For this simple program it does'nt matter.BY any way now i have compiled by gcc

    Code:
    
    asadulla ~/test> gcc temp7.cpp
    execution gcc-3.3.1/gcc (gprs/pcusa_passport_sas)
    asadulla ~/test> ./a.out
    Enter your responses
    1
    2
    3
    4
    5
    6
    2
    3
    4
    4
    5
    5
    5
    5
    12
    Bad responce: 12
    2
    2
    2
    10
    1
    
    
    Rating    Number of Responces
    ------ -------------------
       1             2
       2             5
       3             2
       4             3
       5             5
       6             1
       7             0
       8             0
       9             0
      10             1
    
    
    
     
  5. usama_muneeb

    usama_muneeb Banned

    Joined:
    Mar 7, 2008
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    0
    I have retried under Ubuntu and CRUX Linux. Same output:

    Code:
    root@toshiba:~# gcc 7_2.c
    root@toshiba:~# ./a.out
    
    //blinking cursor ( 10 - 15 mins then termination )
    
    Which OS are you using? Wait, I'll try under GCC 3.

    Code:
    root@toshiba:~# gcc -v
    Using built-in specs.
    Target: i486-linux-gnu
    Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.1.3 --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-checking=release i486-linux-gnu
    Thread model: posix
    gcc version 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)
    root@toshiba:~# 
    I am stuck at this point of arrays for the programs I write complain the same.
     
  6. usama_muneeb

    usama_muneeb Banned

    Joined:
    Mar 7, 2008
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    0
    By the way, which shell are you using? BASH or SH?
     
  7. asadullah.ansari

    asadullah.ansari TechCake

    Joined:
    Jan 9, 2008
    Messages:
    356
    Likes Received:
    14
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    NOIDA
    I am using sun-solaris system
     
  8. usama_muneeb

    usama_muneeb Banned

    Joined:
    Mar 7, 2008
    Messages:
    25
    Likes Received:
    0
    Trophy Points:
    0
    Yep, fine, GCC 3 compiles and runs it smoothly. Thanks for letting me know that there's no bug in code. I think I shan't install GCC 4 until the stable release. Both my CRUX and Ubuntu use 4 and I have installed 3.4 on Ubuntu machine.
     

Share This Page