C :: How To Find MIN And MAX From TXT File

Mar 16, 2013

I just got assigned a project in my C programming class. The objective is to find the min and max number out of a .txt file full of numbers on separate lines called "data.txt". I am pretty much stuck at this point. I don't know how to actually scan the file and print the min and max. Also, the list of numbers in the data.txt file contains hundred on hundreds of numbers. So I couldn't specify the exact amount of numbers listed in the file. I must also find the count number, sum, and the average of the given data, So far I have:

Code:

#include<stdio.h>
int main()
{
int counter=0;
int maximum=0, minimum=1;
int num_data_points, avg;
double max, min;
FILE *sensor;
sensor = fopen("data.txt", "r");

[Code]...

View 6 Replies


ADVERTISEMENT

C :: Reading From A File And Skipping Lines To Find String In File

Nov 26, 2013

Program background: Ticket Sales Details You will sell tickets in advance and at the door. Prices for buying in advance and at the door will be given. Also, the total number of tickets sold in advance will be given. Each guest will have a unique number. If there are n tickets sold in advance, then these guests will be numbered 0 through n-1. As the event starts, requests to buy tickets at the door may be made and these guests will be numbered sequentially, starting at the lowest unassigned number. The maximum number of guests will be 1000. The first line of the file contains the following three values, separated by spaces: Cost of the presales tickets (in dollars), Cost of the tickets at the door (in dollars), and the number of presale tickets. The first two values will be positive real numbers to two decimal places and the last will be a positive integer.

The second line of the file will contain one positive integer representing the number of auction items followed by a positive real value to two decimal places (at most) representing the minimum bid increment, in dollars. The first value is guaranteed to be 1000 or less and the second will be in between 1 and 50, inclusive.

The third line of the file will contain all the prices of the auction items, in dollars, separated by spaces, in order. Thus, the first price is the price of item 0, the next price is the price of item 1, and so on. These values will be real numbers represented to up to 2 decimal places.

The fourth line of the file will contain the three following positive integers pertaining to the raffle: the number of raffle tickets available, the cost of a raffle ticket in dollars, and the number of raffle prizes. (It's strange to have raffle tickets that don't cost a whole number of dollars.)

The fifth line of the file will contain each of the values of the raffle items, in dollars, separated by spaces, in order. Thus, the first price is the price if item 0, the next price is the price of item 1, and so on. These values will be real numbers with upto 2 decimal places.

The sixth line of the file will contain ten positive integers representing the number of each of the drinks 0 through 9, in order, that are in stock.

The seventh line of the file will contain ten positive real numbers with upto 2 decimal places representing the price of each of the drinks 0 through 9, in order.

The eighth line of the file will contain a single positive integer, numEvents, representing the number of events that occur at the charity ball. These events are split into two groups: actions by guests at the ball and awards given (raffle, auction, person, totalrevenue). All of the actions precede all of the awards. You will produce exactly one line of output for each event described. Here are the formats of each event that could occur:

If a patron buys a ticket at the door, a command will be on a line by itself:

BUY TICKET k

where k is a positive integer indicating the number of tickets bought at the door. These guests will be numbered as previously mentioned. You are guaranteed that the total number of tickets bought, including presales, will not exceed 1000. This is what I have so far and I cannot figure out why it wont calculate the total revenue. I am not completely sure if it is even accessing the if statement in main.

Code:

#include <stdio.h> #include <stdlib.h>
#include <string.h>
#define N 1000

[Code].....

View 4 Replies View Related

C++ :: File Read / Find - Miss 1st Line In File

May 3, 2013

I wrote the below code to find the line with "abc" as my parameter to strTosearch. I expected to the line 1st line but, this function always match the 2nd line. What am I missing here?

I wanted "found" to be "abc def hgi SSS".

Code in main()
String found=GetstringColSamLine("mytext.txt", "abc");

File name - mytext.txt
abc def hgi SSS
abc ppp yyy
string GetstringColSamLine(string routerFileName, string strTosearch)

[Code] ....

View 3 Replies View Related

Visual C++ :: Using INI File For Configuring App - System Could Not Find The File

Aug 23, 2013

I am trying to use ini file for configuring my app.

But GetPrivateProfileString is not working.

I am using Windows 7. I tried "Wow64DisableWow64FsRedirection" also.

Not only this-ATLPath::FileExists is also not working.It gives an error code 0x80070002 which means:

"system could not find the file"

View 14 Replies View Related

C++ :: Cannot Find File Specified

Jun 9, 2014

when I try to run the program (new to VC++, I click the green arrow next to "Debug" in the toolbar, right) and I get a message box - code builds without errors - but the debugger says: "Unable to start program 'c:users/sal/documents/visual studio 2010/Projects/SFML App/Debug/SFML App.exe Cannot find file specified"...well, I go to the directory it says, and nothing is even in the Debug file.

View 10 Replies View Related

C++ :: System Cannot Find The File Specified

Apr 4, 2013

I just purchased Visual C++ 2010 Ultimate, to start my coding experience. Whenever I try to debug, it gives me this error:

The system cannot find the file specified

It can't find the .exe file, I even Googled it, and tried a few things, without any luck.

View 2 Replies View Related

C++ :: Cannot Find Or Open Pdb File

Jan 24, 2013

I'm trying to write a program for a pong game using a tutorial online. Every time i try to run my program its telling me "Cannot find or open pdb file" I have tried running Microsoft visual c++ as administrator and checking the box next to the Microsoft symbol server. I only get a black console screen with a blinking cursor.

View 2 Replies View Related

C# :: Could Not Find File PictureBox

Mar 24, 2015

I am working with windows mobile 6.5 and sql compact, trying to create application to save pic on database but when i try to save pic that loaded to picturebox it giving this error "could not find file 'picturebox" and in windows mobile we don't have imagelocation property and this is code that i use it

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

[code]....

View 3 Replies View Related

C/C++ :: System Cannot Find The File Specified

Jun 29, 2014

I can't debug anything and get an error whenever I try. Being able to release a program to run it works sometimes, but it's hit or miss. I've created a very simple program to show the problem. The error on the screen is a result of me trying to debug, but I actually received the same error when trying to release as well.

View 6 Replies View Related

C++ :: Unable To Find Or Open The PDB File

Mar 28, 2014

Code:

'test.exe': Loaded 'C:UsersPcDocumentsVisual Studio 2010Projects estDebug est.exe', Symbols loaded.
'test.exe': Loaded 'C:WindowsSysWOW64
tdll.dll', Symbols loaded (source information stripped).
'test.exe': Loaded 'C:WindowsSysWOW64kernel32.dll', Symbols loaded (source information stripped).

[Code]...

The thread 'Win32 Thread' (0x2d0) has exited with code 1 (0x1).

The program '[6040] test.exe: Native' has exited with code 1 (0x1). my code is not wrong but there is an error which ı dont understand ...where is my error?

View 1 Replies View Related

C :: Find Darkest Point In PPM File Using RGB

Mar 31, 2014

I have write a program to read ppm file and write a new ppm file. However, I'm not sure how to find the darkest point in this ppm file.

Note:
1. there are 610200 RGB point, but my new file only created 176196 RGB point.
2. RGB range: 0-255. (0,0,0)= black; (255,255,255)= white
3. When reporting the location of your dark pixels, assume the upper left corner of the image is location 1, 1

Below is my code:

#include<stdio.h>#include<stdlib.h>
typedef struct {
unsigned char red,green,blue;
} pixel_t;

typedef struct {
int x, y;
pixel_t *data;
} PPMImage;

[Code] .....

Here is ppm file: [URL] .....

View 10 Replies View Related

C :: How To Scan In Numbers From File And Find The Largest

Oct 4, 2013

I'm working on a silent auction program that will scan a file and find the highest from each group of bids, then have a running total of money made throughout the auction. I'm pretty sure the rest of my code works, i'm just getting stuck on finding the largest number from the line in the file, saving it, then moving to the next auction.

input file text (first number is num of auctions, after that it's num of bids, then the bids):

5 4 100 500 250 300 1 700 3 300 150 175 2 920 680 8 20 10 15 25 50 30 19 23

Sample Output
Auction 1 sold for $500.00!
Auction 2 sold for $700.00!
Auction 3 sold for $300.00!
Auction 4 sold for $920.00!
Auction 5 sold for $50.00!

The silent auction raised $2470.00 for charity!

Code:
# include <stdio.h>
# include <stdlib.h>
# include <time.h>

[Code].....

View 4 Replies View Related

C :: Find The Maximum Value In A Column Of Text File

Jul 28, 2014

I have problem with finding the maximum value in a column. This is my code

Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *fp;
fp = fopen ("C:
ocket1.txt", "r");
float time, altitude, velocity, acceleration, amax, bmax;

[Code] ....

The first loop will print out all of numbers in the velocity column. The second while loop is looking for the maximum value in that column. It is supposed to print out the max velocity in the end of the second loop. However, when I build and run the program, it's crashed. I run debugger and received "Segmentation fault" error. When I eliminate the second loop, it run just fine I use Code::Block for text editor.

View 8 Replies View Related

C++ :: Find / Calculate And Replace A String In A File

Feb 3, 2013

i have a text file... with example following content:

Pizza 23232
Car 44,495
Drink 3493,90494
....
..
.

and so on..

no i want to find the 44,495 in this textfile.. calculate a new value like 44,495 x 2 + 5

and write the same file as

Pizza 23232
Car 93,99
Drink 3493,90494
....
..
.

back..

View 2 Replies View Related

C++ :: How To Find And Replace Info In Text File

Jul 1, 2014

I have a program that gives the user the option to create an employee ID, name, address and so on. It also has the option to search employee by employee ID.

What I want to know is how to add and replace employee info. For example employee changes address. Also how to delete employee information from text file.

Here's my code:

//This program uses file input and output for an employee information system.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
ifstream inFile; //declare ifstream as inFile and ofstream as outFile
ofstream outFile;

[Code] ....

View 1 Replies View Related

C/C++ :: Find Number Of Characters In TXT File Without Spaces

Feb 17, 2015

How does one read the number of characters in a .txt file excluding the spaces? Here is my code so far. I am getting 67, which is the correct number including spaces but can't find out how to exclude them. Here's my code!

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
/////////------------------/////////
//Function Prototypes//
int fileLength();

[Code] .....

View 6 Replies View Related

C++ :: Function To Find Sum Of Certain Word In Text File?

Jul 26, 2014

I've written a function that has to receive a word as parameter, and then has to find the amount of times that word (uppercase & lowercase) occurs in a text file:

For example, if the word "the" is sent as a parameter, the total amount of times the words "the" and "THE" occurs in the text file, has to be calculated.

However, my function is not displaying the correct amount, what is wrong with my function:

int WordCount :: countWords(string wrd)
{
int counter=0;
string temp = "";

[Code].....

View 1 Replies View Related

C/C++ :: Program Cannot Find Words In The File If They Are On Another Line

Apr 3, 2015

I wrote this code to search words in the file and display if the program found the word or not. when i write the words in the file on the same line (without the endl) like this :

w_toFile << "gilbert";
w_toFile << "lara";
w_toFile << "rana";
i can search any word.

but when i write them with the endl, the program can find only the first word. what can i do to make the program find any word even if they are each on a line?

here is the full code:

#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
int main (void) {
string wordsearch;

[Code] ....

View 5 Replies View Related

Visual C++ :: Cannot Find The Property Settings File

Jul 31, 2013

Here the max sdk plugin is looking at X:projects rather than x:program files (x86)autodeskmaxsdk Inside the autodesk folder, there is a projectsettingspropertysheets subfolder where the plugin is looking for.

Now an error pops up saying it needs X:projectsprojectsettingspropertysheets....How can I fix that?

<Import Project="........ProjectSettingsPropertySheets3dsmax.general.project.settings.props" />

I find it hardcoded / How do I set where visual studio to search the correct property setting files automatically?

View 3 Replies View Related

Visual C++ :: Cannot Find Relative Header File

Sep 22, 2014

For a while, I have been running a Windows 7 Visual Studio 2012 CPP project fine. However, today, all of a sudden, it has stopped being able to read any header files that are in relative directories. I cannot think what I have done to make this happen.

It seems to be an issue with Visual Studio as a whole, rather than my individual project, because I have created a new simple project and I am having the same problem. So, I have a CPP project at `C:/Projects/TestProject`. Then, I have a header file called `test_header.hpp`, which is located at `C:/Headers`. In `TestProject`'s project settings, I have added the directory `../../Headers` to `Additional Include Directories`. Then, my main functions is as follows:

Code:
#include "test_header.hpp"
int main() {
return 0;
}

Which gives me the error:

Code:
Error1error C1083: Cannot open include file: 'test.hpp': No such file or directoryc:projects estprojectmain.cpp11TestProject

Is there some global Visual Studio setting that is responsible for setting up these relative directories? Just in case the relative directory was not correct, I also tried a load of others, such as `../Headers` and `../../../Headers`, but these gave the same errors.

View 1 Replies View Related

C :: How To Find Number Of Elements In Single Line Of Dat File

Oct 30, 2013

How would i get the total amount of elements From the input file(The .dat file) and then store them in a variable?Here is an example to show you what i want. If a line on the .dat file looked like this

1 2 3 4 5 6 7

How would i find the total number of elements? For example the total number of elements in this line would be 7.

View 9 Replies View Related

C++ :: Find Non Printable ASCII Value - Using Library File Unittest

Jan 3, 2014

My program is find non printable ASCII value(1 to 32) and calculate count from a text like "hi<tab>this<space>my text.i'm using library file here.(visual studio 2012)

removeascii.h(program name)
#pragma once
#include<stdint.h>
#include <string>
using std::string;
namespace ascii

[Code] ....

My ERROR is:

1>c:program files (x86)microsoft visual studio 11.0vcunittestincludecppunittestassert.h(65): error C2338: Test writer must define specialization of ToString<const Q& q> for your class class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >

[Code] ....

View 1 Replies View Related

C++ :: Use Find Function To Search For A Line In Text File

Oct 28, 2013

I'm trying to make a program that will search for a line in a text file using a non default delimitor at the start of the line. An example line in the text file would be as follows:

F Mary Smyth, 19, United Kingdom

I have been able to use the find function to search for and return the 'F' character but would like it to then display the whole corresponding line. Is this possible with the find function?

ifstream readFromFile("data.txt");
string Destinations[1] = {"F "};
string data;
while(!readFromFile.eof()){
getline(readFromFile,data);

[code]...

View 2 Replies View Related

C++ :: Find And Replace Employee Information In Text File

Jul 15, 2014

How to search for a word in a text file and replace it with a new one. Such as employee address, or first name, etc.

Here's my code:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
ifstream inFile; //declare ifstream as inFile and ofstream as outFile

[Code] ....

It is under choice 3, most of my program runs correctly but I am just stuck at this part.

View 3 Replies View Related

C/C++ :: Find Average Of 20 Students By Using A File And One Dimensional Array

Jan 22, 2015

is this according to it??

#include <iostream>
#include <fstream>
using namespace std;
int main(void){
fstream file("textfile.txt");
int linecount = 0;
int tempArray[100];

[Code] ....

View 1 Replies View Related

C/C++ :: How To Find Top 10 Highest And Lowest Numbers From Text File

Jan 3, 2014

I have a list of numbers with decimal point saved in a text file (grade.txt) like this:

80.2
85.7
57.2
90.0
92.9
74.0
76.5
...
I would like to write a small program to display the top 10 highest and lowest grade points.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved