Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Program won't execute (http://www.go4expert.com/forums/program-wont-execute-t9459/)

usama_muneeb 19Mar2008 16:39

Program won't execute
 
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.

asadullah.ansari 19Mar2008 17:43

Re: Program won't execute
 
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


usama_muneeb 19Mar2008 22:03

Re: Program won't execute
 
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++.

asadullah.ansari 20Mar2008 09:56

Re: Program won't execute
 
Quote:

Originally Posted by usama_muneeb
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++.

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


usama_muneeb 20Mar2008 13:10

Re: Program won't execute
 
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.

usama_muneeb 20Mar2008 13:25

Re: Program won't execute
 
By the way, which shell are you using? BASH or SH?

asadullah.ansari 20Mar2008 14:37

Re: Program won't execute
 
I am using sun-solaris system

usama_muneeb 20Mar2008 22:28

Re: Program won't execute
 
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.


All times are GMT +5.5. The time now is 03:37.