For Programmers: Free Programming Magazines  


Home > Archive > C > February 2005 > where does cc send the output by default









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author where does cc send the output by default
Greenhorn

2005-02-24, 8:55 pm

Hi,
when i run the output file generated by using cc i get no output on
my terminal.

#include <stdio.h>
main()
{
printf("Testing the printf functionality");

}
Terminal screen:

[...@localhost ~]$ cc test.c
[...@localhost ~]$ test
[...@localhost ~]$


where do u think the output is going. How should i redirect to the
terminal

greenhorn

Walter Roberson

2005-02-24, 8:55 pm

In article <1109285283.083058.235610@g14g2000cwa.googlegroups.com>,
Greenhorn <teachgreenhorn@yahoo.com> wrote:
: when i run the output file generated by using cc i get no output on
:my terminal.

:[...@localhost ~]$ cc test.c
:[...@localhost ~]$ test

: where do u think the output is going. How should i redirect to the
:terminal

'test' is a built-in unix shell command. You are not running your
program. Try running ./test instead of test

Also, it is fairly common for C compilers to compile to a name such
as a.out if you do not explicitly tell the compiler otherwise.
Commonly, this would be by way of the '-o' option, as in

cc -o test test.c
../test
--
Rome was built one paycheck at a time. -- Walter Roberson
Artie Gold

2005-02-24, 8:55 pm

Greenhorn wrote:
> Hi,
> when i run the output file generated by using cc i get no output on
> my terminal.
>
> #include <stdio.h>
> main()
> {
> printf("Testing the printf functionality");

fflush(stdout);
>
> }
> Terminal screen:
>
> [...@localhost ~]$ cc test.c
> [...@localhost ~]$ test
> [...@localhost ~]$
>
>
> where do u think the output is going. How should i redirect to the
> terminal
>
> greenhorn
>

....but that's not the problem.
<OT>
You haven't run your program at all. Try "./test".
Ask your question at news:comp.unix.programmer for more information.
</OT>

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Artie Gold

2005-02-24, 8:55 pm

Artie Gold wrote:
> Greenhorn wrote:
>
>
> fflush(stdout);
>
> ...but that's not the problem.
> <OT>
> You haven't run your program at all. <oops>Try "./test"</oops>*.
> Ask your question at news:comp.unix.programmer for more information.
> </OT>
>
> HTH,
> --ag
>

*seee Walter's post

--
Artie Gold -- Austin, Texas
DHOLLINGSWORTH2

2005-02-26, 3:55 am


"Greenhorn" <teachgreenhorn@yahoo.com> wrote in message
news:1109285283.083058.235610@g14g2000cwa.googlegroups.com...
> Hi,
> when i run the output file generated by using cc i get no output on
> my terminal.
>
> #include <stdio.h>
> main()
> {
> printf("Testing the printf functionality");
>
> }
> Terminal screen:
>
> [...@localhost ~]$ cc test.c
> [...@localhost ~]$ test
> [...@localhost ~]$
>
>
> where do u think the output is going. How should i redirect to the
> terminal
>
> greenhorn
>

The output buffer, which is lost at exit. Try adding "/n" to the end of
your print statement, or add flushall() before the program terminates.


Keith Thompson

2005-02-26, 8:55 am

"DHOLLINGSWORTH2" <DHOLLINGSWORTH2@cox.net> writes:
> "Greenhorn" <teachgreenhorn@yahoo.com> wrote in message
> news:1109285283.083058.235610@g14g2000cwa.googlegroups.com...
> The output buffer, which is lost at exit. Try adding "/n" to the end of
> your print statement, or add flushall() before the program terminates.


You mean "\n", not "/n". There is no flushall() in standard C; you
probably mean fflush(stdout) (which still doesn't guarantee that the
output isn't, for example, overwritten by the prompt after the program
terminates). (You can flush all appropriate streams with
fflush(NULL), but that's not necessary in this case.)

But in fact that's probably not the problem the OP is running into.
Judging by the prompt, the OP appears to be using some Unix-like
system. The actual problem has to do with the name of the default
output file created by the compiler; don't assume that it's related to
the name of the source file, or that the name "test" is not otherwise
meaningful. The details are off-topic here.

Also, main should be declared to return an int, preferably as
"int main(void)", and there should be a "return 0;" (not required in
C99, and not strictly required even in C90, but still a good idea).

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Hue-Bond

2005-02-26, 3:55 pm

Walter Roberson, jue20050224@23:52:37(CET):
>
> cc -o test test.c


If make is installed, it can be used without a Makefile just with 'make
test'. Plus, it honors CFLAGS.

$ cat > foo.c
int main() { printf ("bar\n"); return 0; }
$ make foo
cc -mcpu=pentium -march=pentium -O3 -pipe -fomit-frame-pointer -funroll-loops
foo.c -o foo
$ ./foo
bar


--
David Serrano
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com