473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Reading an output from another program

Hi,
I'm trying to get this program to read, then print, the output from another short program (hw7.c) it compiles fine but then does not return the values I want it to. I'm assuming I have a problem with my fscanf function. Any help would be great.
Expand|Select|Wrap|Line Numbers
  1.  
  2. /* the idea is to read the ouput from hw7.c and return these values */
  3. #include <stdio.h>
  4. #define FILENAME "hw7.c"
  5. int main(void)
  6. {
  7. /* declare and initialize variables */
  8. float max, min;
  9. FILE *hw7;
  10.  
  11. /* open input program */
  12.  
  13. hw7 = fopen("hw7.c", "r");
  14. if ( hw7 == NULL)
  15.     printf("Error opening hw7. \n");
  16. /* good to go above here */
  17.  
  18. fscanf(hw7, "%f %f", &max, &min);
  19.  
  20. /*print summary */
  21. printf("Max: %f \n", max);
  22. printf("Min: %f \n", min);
  23.  
  24. /* close input program */
  25.  
  26. fclose(hw7);
  27.  
  28. return 0;
  29. }
  30.  

Thanks,
Joel
Nov 15 '07 #1
4 3600
gpraghuram
1,275 Expert 1GB
Hi,
I'm trying to get this program to read, then print, the output from another short program (hw7.c) it compiles fine but then does not return the values I want it to. I'm assuming I have a problem with my fscanf function. Any help would be great.
Expand|Select|Wrap|Line Numbers
  1.  
  2. /* the idea is to read the ouput from hw7.c and return these values */
  3. #include <stdio.h>
  4. #define FILENAME "hw7.c"
  5. int main(void)
  6. {
  7. /* declare and initialize variables */
  8. float max, min;
  9. FILE *hw7;
  10.  
  11. /* open input program */
  12.  
  13. hw7 = fopen("hw7.c", "r");
  14. if ( hw7 == NULL)
  15.     printf("Error opening hw7. \n");
  16. /* good to go above here */
  17.  
  18. fscanf(hw7, "%f %f", &max, &min);
  19.  
  20. /*print summary */
  21. printf("Max: %f \n", max);
  22. printf("Min: %f \n", min);
  23.  
  24. /* close input program */
  25.  
  26. fclose(hw7);
  27.  
  28. return 0;
  29. }
  30.  

Thanks,
Joel
If u are reading the C code , how u can use a float to read it.
It shuld be a char buffer u shuld be using.

Raghuram
Nov 16 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
If you are really going to read the output from another program, then you have to execute that program and not just read its source code.
Nov 16 '07 #3
Ganon11
3,652 Expert 2GB
Maybe you could run hw7.c and store its output in a file, then run this program and read from that file, rather than reading from hw7.c (which will have you reading C code).
Nov 16 '07 #4
AHMEDYO
112 100+
HI...

if i understand you correctlly, you must create your exe file from hw7.cpp program and use API createProcess to run it and then use Pipe to read output from it.
Nov 17 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Rafal Lagowski | last post by:
Hi all This is my small problem ... I have a program which make a long long statistic (about 2 minutes) It enough to timeout in my browser (or squid proxy of client) I want first make a...
0
by: federico | last post by:
Hello, how can I make a program respond to another program's input request? For example, this code: Process.Start("unrar.exe", "e D:\temp\key.rar D:temp2") SendKeys.SendWait("test~") will...
18
by: utab | last post by:
Dear all, I am making a system call to the well known Gnuplot with system("gnuplot"); gnuplot opens if I only supply this command but I would like to pipe that command line in my C++...
1
by: Stuart Moore | last post by:
I've tried searching for the following, but I've had no luck. I want to execute another program from within my C++ program, and read it's stdout in a similar way to reading from a file. I do not...
3
by: 31337one | last post by:
Hello everyone, I am using a python script as a way to test another program that I have written in C++. The program cannot be altered. It needs to stay the way it is. I need to simulate a few...
1
by: Netaro | last post by:
Well... So, i have a program. A normal program, which does something, and so.. and i have another program, which wants to run the first program.... So, there are 2 questions about that problem...
2
by: jrbush82 | last post by:
I am trying to read the standard out of another program into an array or string in my C++ program. I need to read each line individually because based on the output depends on what the program will...
3
parajaganesh
by: parajaganesh | last post by:
I have a program which results some output (it is in an array). These outputs need to be passed to another program for further process. Anybody help me to do this...?
1
by: WackoZacho | last post by:
I've tried searching on Google and for other questions similar to mine, but all I get are results on how to use the LostFocus event or Deactivate, etc., but I'm under the impression each of these...
4
by: maximus tee | last post by:
hi all, i wrote a simple GUI with 2 buttons. Button1 is to launch another program. Button2 is to run test. When I click Button1, it will launch another program. After launching the program, my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.