C++ :: File Is Not Reading Properly?
Mar 30, 2013
I have a file which I am unable to read properly. This is binary file so my code is"
#include<iostream>
#include<fstream>
#include<string>
[Code]....
the file to read can be download from this link :
[URL]
The first content of file should be 1 I am missing few content from the begining
View 2 Replies
ADVERTISEMENT
Apr 11, 2014
I'm parsing an xml file full of payslips and using the data in another application. I've got it all working but I suspect it isn't the most elegant piece of code. I run through the xml file finding a series of "Text" attributes/elements" and then I run through it again finding a series of "Field" attributes/elements, Here is a sample of the code:
For getting the "Text" fields :
XNamespace ns = "urn:crystal-reports:schemas:report-detail";
//
// Get all the Text attributes & Elements
//
foreach (XElement xtxt in xdoc.Descendants(ns + "Text"))
[Code]...
This works fine, I extract all the data I'm interested in and go to do my thing with it. However I really need to know when each record ends and I was doing that by looking for "Text24" in the text fields and "EeRef2" in the field fields, which wasn't very elegant in the first place. Then a "Text16" was added to end of each record which was fine I could just look for "Text16" but now it's apparent that "Text16" isn't always there. I've got it all working for now but I'd prefer to process one record at a time i.e. extract all the "Text" & "Field" values for one record, do whatever I need to do with it, update the xml file to indicate this progress ( if possible ) and then move on to the next record. I've attached a sample of the xml but basically is has the following structure :
<Details>
<Section>
<Text></Text>
"
<Field></Field>
[Code]...
So a record is everything between the first <Details> and the last </Details> with two <Details> and two </Details> in between.
View 2 Replies
View Related
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
Nov 7, 2014
I am reading a file then printing the data onto the other file. It is working, however when I check to see if each variable is being properly set after reading the file a issue arises.
Example of the file being read
Code:
Vehicle PV50CAN passed camera 1 at 05:33:26.
Vehicle W867BRO passed camera 1 at 05:33:29.
Vehicle KQ63ARU passed camera 1 at 05:33:38.
Vehicle K954ITQ passed camera 1 at 05:33:40.
Vehicle V220MXB passed camera 1 at 05:33:42.
[Code] .....
View 14 Replies
View Related
Aug 26, 2014
I am unable to get the string seaching function to work. it always says "Nothing found" I am stumped.
Code:
#include <stdio.h>
#include <string.h>
char tracks[][80] = {
"I left my Heart at Harvard Medical School",
"Newark, Newark, You suck balls",
"Dancing with a dork",
"From Here to maternity",
"The Girl from Iwo Jima",
[Code]....
View 3 Replies
View Related
Mar 5, 2013
1. In main() in the while loop entering 'q' does not exit.
2. in the isbnValidation function. The size check for minimum length words will work, but the check for "Invalid ISBN character" doesn't.
3. Every ISBN entered returns as valid. The formula is supposed to multiply the first digit by 10, next by 9 etc (skipping all the dashes) and add up to a weighted total which if valid will divide evenly by 11.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ISBNMIN 10
#define ISBNMAX 14
[Code].....
View 4 Replies
View Related
Oct 31, 2013
so i have a container called Source that is of type std::map<std::string, std::vector<std::string>> but when I try to print it with this function:
void Lexer::PrintSource()
{
for(auto Iterator = this->Source.begin(); Iterator != this->Source.end(); Iterator++)
for(auto SubIterator = Iterator->begin(); SubIterator != Iterator->end(); SubIterator++)
cout<< *SubIterator << endl;
}
i get these errors:
Lexer.cpp: In member function 'void Lexer::PrintSource()':
Lexer.cpp:29:42: error: 'struct std::pair<const std::basic_string<char>, std::vector<std::basic_string<char> > >' has no member named 'begin'
for(auto SubIterator = Iterator->begin(); SubIterator != Iterator->end(); SubIterator++)
^
Lexer.cpp:29:76: error: 'struct std::pair<const std::basic_string<char>, std::vector<std::basic_string<char> > >' has no member named 'end'
for(auto SubIterator = Iterator->begin(); SubIterator != Iterator->end(); SubIterator++)
^
View 6 Replies
View Related
Sep 29, 2014
#include <iostream>
using namespace std;
int main()
{
[Code]...
For some reason, I get the cout of
321
1
Because of the a++, shouldn't it be
321
2
The second example is what the cout needs to be.
View 1 Replies
View Related
Sep 2, 2013
If I were to exit a program, is it okay if I fail to properly destroy whatever structures were allocated?
For instance, if I do this with SDL, there might be obvious consequences like a dead window perhaps. But if I do this with a POD structure, is it okay?
Also, I realize RAII is supposed to fix parts of this but it's not perfect when environments are suddenly cut off with something like exit(1/0);
View 2 Replies
View Related
Jun 12, 2012
I'm using MS' optimizing compiler CL 13.10 (one from VCToolkit 2003) along with WinAPI threading functions and is being compiled as a C console program.
I was wondering how to implement threading in a production setting? I've seen and tried various examples, but they all show basically the same thing - startup in main, run their function, clean up, and then the program exits.
I don't know the proper terminology, but I was looking for two maybe three functions to run simultaneously with a loop in main. I tried a small test program and was wondering if it's setup correctly.
A structure is used as the argument for each function.
int running = 1; // global variable
DWORD WINAPI function_1(LPVOID);
DWORD WINAPI function_2(LPVOID);
main() {
HANDLE hndThreads[2];
DWORD threadIDs[2];
[code].....
Right now, function_2 is just a copy of function_1's definition. Everything *appears* to do what I want, but is it setup correctly?
View 2 Replies
View Related
Apr 4, 2013
#include <iostream>
using namespace std;
int function(int a,int b) {
return a + b;
} bool function2(int a,int b)
[Code] .....
View 3 Replies
View Related
May 21, 2013
This is my code for submitting students but when i use search function the course member is empty
Code: #include "windows.h"
#include "iostream"
#include <io.h>
#include <sstream>
#include <conio.h>
#include <stdlib.h>
#include <iostream>
#define SIZE 5
using std::cout;
using std::cin;
using namespace std;
int menu();
[code].....
View 11 Replies
View Related
Apr 9, 2013
I' used to check if my streams are properly opened with a simple:
Code:
if (!file)
std::cout<<"Error message";
However I just realized this is only a valid test if they are initialized with a wrong string and when I tested it:
Code:
int main() {
ifstream f_one("input.txt");
ifstream f_two("not_a_file.txt");
ifstream f_three;
[Code] ....
I didn't get the f_three error message, only the f_two.
how should I check my streams in order to prevent this?
View 6 Replies
View Related
Mar 20, 2013
i am facing some problem with qsort() function it work well if the last element of array is larger then the 2nd last element. But in case if last element of array is smaller then the 2nd last it will sort the whole array and remains the last as it is. For example
Code:
int group_id_local[max_j]={2,1,4,5};// it work fine, output should be {1,2,4,5} but if i have this one
int group_id_local[max_j]={2,1,4,3};
// output should be {1,2,4,3}
/* COMPARE FUNCTION FOR USING QSORT()*/
int cmpfunc (const void* a, const void* b)
{
if (*(int *)a < *(int *)b) return -1;
if (*(int *)a > *(int *)b) return 1;
return 0;
[Code]....
why it will not sort the last element?
View 5 Replies
View Related
Oct 24, 2014
I'm trying to fill the array "g" with letters from the array "letras" given a certain condition. Everything is working fine, except I couldn't do it... Strange characters appear when I run the code. What am i doing wrong?
Note: This is a part of a function. "vetor" is a parameter that was passed to this function.
Code:
int i;
int j = 0;
char g[20];
char letras[5] = {'a', 'b', 'c', 'd', 'n'};
while(j < g)
{
for(i = 0; i < 80; i = i + 4)
[Code]...
View 3 Replies
View Related
Oct 19, 2013
I want to alter a string inside a function, but it is not working.Here is the function:
Code:
#include <stdio.h>
void test (char *ch){
ch[0] = 0;
ch[1] = 1;
ch[2] = '';
}
[code]...
View 2 Replies
View Related
Dec 16, 2013
this programm should in theory create a labyrinth but it doesnt and i really dont have the skill to pick up where i have been mistaken so gcc runs it but it crashes and it doesnt produce any remarkable results even when it runs....
for example this should you run it with these parameters .
5
5
appear something like this
10111
10101
10101
10001
11111
or like this
10111
10001
11101
10001
11111
but it only crashes....it works with recursion and it makes a array (which is Ptr) a set of 1 and 0 which 0 is the path and 1 is the walls...
Code:
#include <stdio.h>#include <stdlib.h>
#include <time.h>
int **Ptr;
int M, N, P, charge, i,c,j;
void Lab_creator(int vertical, int horizontal,int direction);
[Code] .....
View 2 Replies
View Related
Jan 4, 2013
For some reason the integer array, arr[100][50], declared in main is not storing the correct values when passed through the function charArrayToIntArray.
I made an output right in the function to show how the array is not keeping the proper values, although when I output the array from within the loop in the function, it shows the correct values.
/*
infile.txt:
37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676 ...........
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cstdio>
#include <sstream>
#include <iomanip>
using namespace std;
void fileToCArray(string carr[100]); // from text file: inputs the 100 50-digits number into an array of 100 50-character
[Code] ....
View 4 Replies
View Related
May 24, 2013
For example, if one researched how to deep copy a map container and paraphrased a solution from a website, what is the proper format? Are there standards for citing works in code?
I am currently only citing the link to the source in my personal code and explaining what algorithm the source contains.
View 4 Replies
View Related
Nov 1, 2014
I am creating a right hand maze solution, and it actually works for the most part, but it gets stuck at the sixth spot and will not proceed any further. I cannot seem to find my error even though I know it's probably a small one in my code, here is what I have at the moment:
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
[Code].....
View 6 Replies
View Related
Feb 9, 2015
I have an application that uses an array of threads to call a method along with thread.join(). I was just wondering what would be the best way to handle the thread in case if one of the thread fails? Should I put a try catch block on the method that is being called or should I put the try catch block on the array of threads, or is there any other proper way to handle failed threads?
View 3 Replies
View Related
Feb 4, 2015
I'm trying to write a wrapper for rapidXML in order to use it in my projects however I've run into a curious bug that's preventing me from properly saving the XML documents I'm working with. The gist of it is: simply parsing a very simple xml doc and then saving the same document to the same file (without modifying it) creates a mostly correct output except for scrambling a few node closures:
bool rXMLwrapper::parse(){
try{
std::ifstream file(filepath.c_str());
if(!file.is_open()){throw std::bad_alloc();}
std::stringstream buffer;
buffer << file.rdbuf();
file.close();
[code]....
I'm using this patch for rapidXML: [URL]
As a foot note: I'm almost certain it's not an issue with the parse() function.
If I parse() the document and then call std::cout<<doc; it prints the document perfectly fine to the console, but for some reason std::ofstream<<doc; causes issues.
View 1 Replies
View Related
Dec 21, 2014
I'm writing a program where the user inputs a number of rows, and that many rows of @ symbols are printed, where the first row has the same number of columns as rows, and each next row decrements the number of columns by 1. It prints out a totally wrong output and whatever I try it won't print the right thing- currently when I input 4 it prints out 5 @ symbols on the first row, and then 3 on all the other rows.
Code:
#include <iostream>
using namespace std;
int main ( ) {
int rows;
cout << "How many rows? ";
cin >> rows;
[Code] .....
View 2 Replies
View Related
Jun 16, 2014
I would like to know how to make Lynx follow meta refresh links automatically, At the moment it just provides a "clickable" link you can accept the refresh. I would like this to be automatic.
--- Initial problem ---
We have a DB Backup script written in PHP/HTML and uses the page refresh to loop the backup (every 2 minutes). Using a full fledged browser is not really an option on our machine as the resources are very tight. So we tried Lynx and it has the perfect footprint but the only problem is it doesn't refresh the page.
I'm thinking I just need some way to force Lynx to reload the page after the time has elapsed. Maybe create a new function that starts a timer and hold the url until the timer ends then force Lynx to visit that url. Im a PHP Procedural kinda guy and I cant think how to set this timer event safely without corrupting or crashing the program or creating memory leaks.
(source code im using: [URL])
This is the function that handles meta refresh.
Code: /*
* Given a refresh-URL content string, parses the delay time and the URL
* string. Ignore the remainder of the content.
*/
void LYParseRefreshURL(char *content,
char **p_seconds,
char **p_address)
[code].....
View 4 Replies
View Related
Mar 6, 2013
My code won't run properly. The error says unresolved externals.
#include <iostream>
#include <cstring>
using namespace std;
char again;
void reverse(char*);
[Code] ....
View 2 Replies
View Related
May 11, 2014
I'm working on a class that needs to read from cin, but also needs to read the input twice. I've decided that the mechanism I want to use is to write a simple wrapper class that will read from cin, then write to a tempporary file in the operator>> method, then it will, when the application calls seekg(0) to reset the file to the beginning of the file, my helper class will just switch the underlying stream from cin to the temporary file, then return reads from there.
I know there are some underlying issues to address if I need MORE functionality later, but for now, I know the basic functionality I need and from a logic level and how to make that happen. What I don't know how to do is handle the syntax of overloading the operator>> method.
I'm looking for a good syntax reference, or some sample code of how to properly overload this from a stream SOURCE perspective. I've written plenty of classes that overload operator>> from the DESTINATION perspective, but the exact same prototype doesn't work, at least not for primitives.
View 3 Replies
View Related