Link to home
Start Free TrialLog in
Avatar of komlaaa
komlaaa

asked on

compile but ....

Thanks you Van_dy and u all.

I finally compile this program but when i run
./executable inputFile name   OR
cat inputFile | ./executable

the file fails to open.  Van_dy, i send u the th program, please take a look.
Here is my sample run:
=================== ERROR ==================
cs450/a4_1> ls
BUG_LOG  Makefile  TIME_LOG    error     getopt.o  main.cppn  wc.cpp  wc.o
MANPAGE  README    cs450words  getopt.c  main.cpp  main.o     wc.h
cs450/a4_1> cat Makefile

all: cs450words

cs450words:  wc.o main.o getopt.o
        g++ main.o wc.o getopt.o -o cs450words

wc.o: wc.cpp wc.h
        g++ -g -Wall -ansi -c wc.cpp

main.o: main.cpp
        g++ -g -Wall -ansi -c main.cpp

getop.o: getopt.c
        cc -c getopt.c

clean:
        /bin/rm -f cs450words main.o wc.o getopt.o *~

cs450/a4_1> uname -rs
Linux 2.4.27
cs450/a4_1> ls
BUG_LOG  Makefile  TIME_LOG    error     getopt.o  main.cppn  wc.cpp  wc.o
MANPAGE  README    cs450words  getopt.c  main.cpp  main.o     wc.h
cs450/a4_1> cat Makefile

all: cs450words

cs450words:  wc.o main.o getopt.o
        g++ main.o wc.o getopt.o -o cs450words

wc.o: wc.cpp wc.h
        g++ -g -Wall -ansi -c wc.cpp

main.o: main.cpp
        g++ -g -Wall -ansi -c main.cpp

getop.o: getopt.c
        cc -c getopt.c

clean:
        /bin/rm -f cs450words main.o wc.o getopt.o *~

cs450/a4_1> uname -rs
Linux 2.4.27
cs450/a4_1>cat MANPAGE | ./cs450words
No input file provided
cs450/a4_1>



Avatar of van_dy
van_dy

I will take a look at it, and will let u know in a while
Avatar of Kent Olsen
Hi komlaaa,

In general, if you'll provide the problem code then all of the experts here will be able to jump in and help.  This will usually get you answers more quickly than addressing queries to an individual.

Offhand, I'd suggest that you're not reading from stdin.  You can do this a couple of ways.

Whenever you issue a stream input function like fscanf(), fgets, etc, make sure that the target stream is stdin.

If you've already got another stream name embedded throughout your program because you tried to open the file, simply replace the fopen with this statement:

  SomeStream = stdin;   /*  Assumes that you have a FILE *SomeStream; declaration in the program  */


Good Luck,
Kent
ASKER CERTIFIED SOLUTION
Avatar of van_dy
van_dy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi komalaaa,

As I mentioned earlier, please post the problem here.  With rare exception, it is against the rules to take these discussions offline as this defeats the purpose of the Exchange.  If a problem is worth solving, it is probably of interest to others, so taking the discussion offline deprives others of the opportunity to learn and reduces EE to a signup sheet for private tutoring.

Also, your problem is obviously C++.  This question should be in another forum.

Kent
Avatar of komlaaa

ASKER

Hey Kent,

Sorry if that is what my method for getting helped out imply.
I will conider your concern in future.

Thanks.

Komlaaa
LOL, i think i need to add to this.

komlaaa: kent is very right regarding the purpose of exchange. The problem should be brought
                forth for all the experts to look at so that every one can give it a shot. you should post
                 your source files here itself.

kent:       actually the problem has been open for quite a while, starting with this post:
  https://www.experts-exchange.com/questions/21173430/undefined-reference-to-getopt-int-char-const-char-const-'.html
the discussion above apparently failed to solve the problem for him because the same problem came
up again later  in this post -> https://www.experts-exchange.com/questions/21175106/running-getopt-on-solaris.html
komlaaa was having issues with linking properly to libc on his solaris machine from a c++ program
which happened to use getopt(). you can sure follow the post to see how did it eventually get resolved.
from then onwards, i have basically helped in putting together various translation units in a makefile
to produce an executable which actually is not much work if you have all the source files with you. komlaa
sent me his sources since none of the experts were involved in the discussion at that time.The
present question is definitely c++ not c, however since i already knew the nature of the problem, it would
be apt for me to help if i could, and that is what i am doing.

peace.
Avatar of komlaaa

ASKER

i would like to reiterate to kent i am currently on C forum because of the problem i was with getopt.c(like Vand_dy mention)
that i need to link to C++ program. However, i agree that if i posted a problem not an individual, i will be more helped out quickly. i will consider this in future.

Thanks u all and peace!!!

komlaaa
Avatar of komlaaa

ASKER

I am surprised i did not have to implement the bothe version of read but only istream one to get it working in both way. i left the main as u recommended.
Any Comment.

Thanks,

komlaaa
yea there is a reason to it,
take a look at this
http://www.cplusplus.com/ref/iostream/
i havent actually done this, but i guess you can do it just for istream and use the same function for cin,  ifstream, istringstream