Ask your own question, for FREE!
Computer Science 11 Online
OpenStudy (anonymous):

How do you read in a file from stdin? I need to include the text file to be read when compiling so I can't hard code a specific file name in my code. This code grabs a line from a file: fgets(inputLine, MAX_LENGTH, stdin) the 3rd parameter is the file pointer. However just stdin does not work, I must include something else to get it to read a line. What am I missing? Example of line when compiling: clang -Wall readInFile < textFile.txt

OpenStudy (anonymous):

This confuses me because stdin is expressly designed to work just like any other FILE*. Like, it's part of the point of the c library that it works like that. Are you sure your command line isn't what is doing it?

OpenStudy (anonymous):

I was using a Makefile, but since I didn't want to add the file in just yet I just did it on one line. I actually compile three programs at once. Compiling line: clang -Wall something.h something.c main.c < textFile.txt When I run, the program will just get stuck in a loop when trying to read the textFile. I put a printf in the loop and nothing was being printed out like it should have.

OpenStudy (anonymous):

Wait, are you trying to put in the text file at compile-time? You can't do that. You have to compile it and then run it with textFile.txt fed to it.

OpenStudy (anonymous):

I totally forgot that was how you did it >_< thanks!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Countless7Echos: Ah trying out the whole T.V girl drawing :p (I love drawing eyes)
1 hour ago 8 Replies 5 Medals
kaelynw: starting to draw a hand
2 days ago 16 Replies 2 Medals
Twaylor: Rate it :D (Took 2 days)
2 days ago 7 Replies 0 Medals
XShawtyX: Art, Short Writing Assignment: Imagining Landscapes
4 hours ago 7 Replies 1 Medal
XShawtyX: Chemistry, Help ud83dude4fud83cudffe
3 days ago 13 Replies 1 Medal
kaelynw: tried a lil smt, the arm is off but i like the other stuff
3 days ago 27 Replies 3 Medals
kaelynw: art igg
3 days ago 14 Replies 1 Medal
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!