The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
simple awk question orahi001 UNIX for Dummies Questions & Answers 2 01-11-2008 06:16 AM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 09:03 AM
Simple FTP question fundidor UNIX for Dummies Questions & Answers 2 04-28-2005 06:59 PM
a very simple question (but i don't know) dell9 High Level Programming 1 10-29-2001 11:37 PM
Simple question? Cuthbert UNIX for Dummies Questions & Answers 5 07-16-2001 10:00 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-13-2006
Registered User
 

Join Date: Dec 2006
Posts: 4
Simple C question... Hopefully it's simple

Hello. I'm a complete newbie to C programming. I have a C program that wasn't written by me where I need to write some wrappers around it to automate and make it easier for a client to use. The problem is that the program accepts standard input to control the program... I'm hoping to find a simple way to modify the program to also accept input from a text file instead. Can someone please help me with this? I know my post is very vague, but hopefully someone can help guide me. Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-13-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 923
You don't need to modify the program at all, since UNIX lets you redirect standard input to read whatever you please. A simple shell script wrapper can do this, for example:
Code:
#!/bin/sh
exec /path/to/program < input_file.txt
Reply With Quote
  #3 (permalink)  
Old 12-13-2006
Registered User
 

Join Date: Dec 2006
Posts: 4
Unfortunately redirecting the input to get it from a file doesn't work. It answers the first question correctly, but the answers after that don't get the correct answers...
Reply With Quote
  #4 (permalink)  
Old 12-13-2006
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 923
Without more details, or the code in question, I don't know.
Reply With Quote
  #5 (permalink)  
Old 12-14-2006
Registered User
 

Join Date: Dec 2006
Posts: 4
I know it's hard to help me because I'm being so vague. I'm also having a hard time explaining exactly what I need to do without showing the code.
Reply With Quote
  #6 (permalink)  
Old 12-14-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 3,502
It sounds like you may want a utility called expect - it lets you create fairly complex interactive dialogues with a program - from a script.

expect scripts are easier to create than C code...

The here document - do you know what those are? Will they meet your needs?
Reply With Quote
  #7 (permalink)  
Old 12-15-2006
Registered User
 

Join Date: Dec 2006
Posts: 4
Actually, I decided to take a few hours and read about C Programming. I figured out how to approach the code and found a solution. Thank you guys very much for the help.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0