473,385 Members | 2,269 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,385 software developers and data experts.

File I/O & Array Problem!

2
Hi there. I have been given an assignment to do which counts towards my final grade but I'm struggling quite badly with it.
THE TASK
Write a program which reads 10 numbers from a file indata.txt, finds the minimum and maximum value, and writes them out to a file result.txt within a message.
For example, if the content of indata.txt is:
4 9 2 -10 8 126 0 45 -313 92
the content of result.txt must be
The minimum value found is -313, the maximum 126


Here is what I have so far...

#include <stdio.h>

int main(void)
{
FILE *fp = fopen("indata.txt", "r");
if (fp == NULL) {
fprintf(stderr, "Can't open input file %s!\n", indata.txt);
exit(1);
}

ofp = fopen("result.txt", "w");
if (ofp == NULL) {
fprintf("Can't open output file %s!\n", result.txt);
exit(1);
}

float min(float a[], int size) {
assert(size < 0);
float minVal = a[0];
for (int i=1; i<size; i++) {
if (a[i] < minVal) {
minVal = a[i];
}
}
return minVal;
}//end min

float max(float a[], int size) {
assert(size > 0);
float maxVal = a[0];
for (int i=1; i<size; i++) {
if (a[i] > maxVal) {
maxVal = a[i];
}
}
return maxVal;
} /*end max*/


fprintf("Minimum = %f\n", minVal); /*prints min value*/
fprintf("Maximum = %f\n", maxVal); /*prints max value*/

return 0;
}

If you could help me in any way with this I would be extremely grateful.

Thanks
Mar 3 '08 #1
3 1403
oler1s
671 Expert 512MB
You need to ask a question. (A code dump is not a question.) You also need to learn to use CODE tags, because unformatted code is unreadable. From reading the forum rules, you should realize that we, like other technical forums, have pretty strict rules in helping with homework questions. Do not dump code, and sit back hoping for us to do the rest of the work.
Mar 3 '08 #2
nr7489
2
Oh no thats not the case at all. I need help thats all need pointers and tips to help me take the problem forward.
Mar 3 '08 #3
mac11
256 100+
Oh no thats not the case at all. I need help thats all need pointers and tips to help me take the problem forward.
People are glad to help with a specific task if you narrow it down and explain your issue(s).

What exactly is giving you trouble? What part of your code is broken? What don't you know how to do that you need to do?
Mar 3 '08 #4

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

Similar topics

0
by: Phil Powell | last post by:
// PROCESS XML CONTENT INTO DYNAMICALLY-NAMED ARRAYS foreach (array('mime', 'state', 'country') as $val) { $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);...
4
by: Shock | last post by:
Hi everybody, I have been getting so much good advice here that I figured I would post another question. I am still learning c++ from a text that I inherited from my brother. I am now working...
6
by: tsirman | last post by:
hello can i put in an xsl file variables from php??? well i have 15 xsl files which have many "<a href.........." with the url of the project. so if i want to make my project portable i must have...
11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
16
by: Steven T. Hatton | last post by:
In the following code, the only way I can figure out to pass an array of const is by setting the template argument to const in the instanciation expression. It would be (or seem to me) better if I...
4
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know...
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
5
by: Grant Harmeyer | last post by:
I have an application that uses FreeTextBox 2.0 (http://www.freetextbox.com). FreeTextBox is a rich text editor that behaves similarly to MS Word. The FreeTextBox control has a button to insert...
3
by: Ahmad Jalil Qarshi | last post by:
Hi, I have a text file having size about 2 GB. The text file format is like: Numeric valueAlphaNumeric values Numeric valueAlphaNumeric values Numeric valueAlphaNumeric values For example...
3
by: hutch75 | last post by:
Question could also be asked, how to compare data between two arrays and perform an action (print cmd) everytime there is a match? The problem I'm having with the code below is that the comparison...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.