C++ :: Working With Strings / Files And Time-tag Calculation

Dec 27, 2012

I'm trying to calculate a series of times from start to end, and find out the duration between them, sum them up and see if they're above a certain value or not, for each particular instance.

My goal is to provide a prepared text file with time tags such as this:

Mon 19-Nov-2012 09:12 Mon 19-Nov-2012 09:34
Wed 21-Nov-2012 13:14Wed 21-Nov-2012 17:11
Fri 07-Dec-2012 15:21Fri 07-Dec-2012 15:26
=============================================
Mon 26-Nov-2012 12:50Tue 27-Nov-2012 15:29
Wed 12-Dec-2012 13:07Wed 12-Dec-2012 14:58
Fri 14-Dec-2012 14:22Fri 14-Dec-2012 14:29

And the program is able to calculate the total time relevant to each instance (instances separated by a line of '=').

Some form of number should somehow identify each instance or something similar and a text file is generated with total time printed for each instance. E.g.

Instance 1: 00h22m + 03h57m + 00h05m = 04h24m
Instance 2: 04h15m + 07h44m + 01h51m + 00h07m = 14h04m

Now I'm currently working on making the logic to calculate time within the ranges I'd like based on several parameters.

Are there any references I can use when it comes to working with strings in order to seek and extract these values in order to work with them? The documentation available on this website, despite being very informative, does not show practical applications of said class and I'm at a loss on how to implement the functionality.

View 17 Replies


ADVERTISEMENT

C++ :: Average Calculation Function Not Working As Expected To

Dec 16, 2013

[URL] ....

My calculation function will not work like i wanted it to. It gives me 0 or a crazy number.

this is the function here:
the entire code is on the link:

double calculations(data&avgs) //Calculates the students grade into a final grade
{
int avg1;
int avg2;
int avg3;
int lab1;

[Code] ....

View 12 Replies View Related

C++ :: Simple Calculation Going To 0 Every Time

Aug 8, 2013

I tried to write a simple program to calculate monthly yield, APR, and principle in various directions. Anyway, here's some code to get the APR from the principle and monthly yield. When I run it though, it spits 0 at me every time! What the problem is; the other functions work just fine and the code line for the APR calculation is just what it ought to be - I see neither a math nor tech problem here.

Here is the offending function:

Code:
void calculateAPR() {
int principle, monthlyYield, apr;
cout<<"
Please input the principle:";
cin>>principle;
cin.ignore();

[code]....

View 4 Replies View Related

C++ :: Possibility Of Compile Time Calculation

May 13, 2013

Is there any possible way of calculating some values at compile time? I have the following code of genereting upto 2000000010 palindrome numbers.

Code:
#include <iostream>
#include <string>
#include <sstream>
#include <string.h>
#include <stdlib.h>

[Code] .....

As you see, I have taken input from the user just after calculating the whole palindromes. So cant we calculate this at compile time? because runtime of this program is extremely slow.

Another qs. I first tried to use array but It didnt allow 2*10^9 sized array. so what should I do whenever I need that size of array?

View 12 Replies View Related

C :: Concatenate Strings In Array (2D) - Function Not Working Right?

Sep 6, 2013

I have a function that concatenate the strings in an array(2D)

Ex 1: Sean Connery Micheal King James Wood

Result: SeanConnery MichealKing JamesWood ...

The concatenation function working correctly and displays correctly in the function. But if I make another function to display it, it shows this

Ex 2: SeanConnery Sean MichealKing Micheal JamesWood James..

It adds to first name. Why?

Code:
void Concatenation( char dest[200][13] ) {
// loop through and concatenation the strings
for(int i=0;i<200;i+=2) {
myStrCat(dest[i],dest[i+1]); // mystrcat is equalto strcat()

[Code] .....

View 4 Replies View Related

C/C++ :: Bubble Sort Not Working For Array Of Strings?

Apr 9, 2015

I am trying to sort an array of strings but when I pass it through my bubbleSort function, it gives me a segmentation fault. By print checking, I know that there are strings in the array "f" but it doesn't get sorted.

Note: The file I am putting into this program is a text file with 1000 lines

# include <stdio.h>
# include <stdlib.h>
# include <string.h>

[Code].....

View 1 Replies View Related

C++ :: Working With Files In Netbeans

Jul 26, 2013

I have created a project in netbeans 7.2 and have not modified any setting. I have used all sorts of methods I could think/find but the code can not find the file.

I have placed my test.txt file in the folder of the project. Here is the location of the file:

C:UsersSAMARASDocumentsNetBeansProjects
eadFi le

However, I could not use it without modifying it as an absolute path.

For example, check the code from the FAQ. //well the return 0; is missing but this is not the problem now.

Or for example this code Code: bad code or with Code: myReadFile.open("C:/Users/SAMARAS/Documents/NetBeansProjects eadFile est.txt"); I have tried many things for placing the slashes, but could not find the file.

View 6 Replies View Related

C :: Working With Files / Struct And Manipulating Data

Dec 17, 2013

I have the following code and I am trying to do simple math calculations to the data. I need to take the car price (y) minus down payment (z) and then divide that quantity by 12 times "yearsx" That answer is then assigned to x. The problem is that x will not print the correctly!I also noticed that if I increase the "count" to amnything higher than the number on lines in the file, I get the correct value for x but only on the last set of the struct..my file reads as follows:

last_name first_name car_price down_payment years
johnson bill 10,000 2,000 3

When I printf the struct to the screen, i need to do the following:

x = (10,000 - 2,000)/(12*years);

but this is the math part that wont work. I have checked and doubled checked number types and I cant get it right.

Code:

#include<stdio.h>
#include<stdlib.h>
#define FILENAME "file.txt"
#define SIZE 100
}

[code]....

View 3 Replies View Related

C++ :: Search Array Of Strings - How Many Time Word Was Used

Feb 4, 2013

The function should search the array of strings to find how many times the word 'the' was used. but its only returning a 0.

int FindThe (int The, char Paragraph[], char Pattern[]) {
for (int i(0); i < 500; i++) {
if (Paragraph[i] == Pattern[0] {

[Code] ....

View 5 Replies View Related

C++ :: Embedding Version Strings At Build Time

Dec 11, 2013

I have a set of projects. Each one builds either a static library or an executable. What I'd like to do, is at build time I want to embed a version string representing the version of the executable as well as the version of each library. These version strings will come from an external source (in my case it's based on a "git describe" call, but that's beside the point). Embedding such strings can be highly valuable for traceability. (Versions of 3rd-party libraries are not necessary.)

I'm using qmake as my build system, but this should work more or less similarly with any build tool. What I'd ideally like to do is define this process in such a self-contained way that a an absolutely minimal amount of additional code is required in order to leverage it. Preferably, nothing more than an include(version.pri) in each project's .pro file in order to collect the versions. (Retrieving them later, such as to respond to a --version command-line flag, can be done via traditional C++ methods.)

What I've done so far is to define a singleton VersionTracker class, and then tweak the build system so that "MODULE" and "VERSION" are preprocessor symbols defined at build time. I've also tweaked the build system so that a file in each project, version.cpp, is rebuilt (and regenerated if necessary) on every build regardless of changes. This source file can capture the information in the preprocessor symbols into each static library and the executable.

Now, here's the problem. How can I get the information from those version.cpp files into the VersionTracker class? I thought I could use a global object's constructor to do it, but it turns out the symbols are stripped out when the static libraries are linked so I only get the executable's version. I also found a page on stackoverflow detailing a very clever way to call a registration function at class definition time, but again the class definition appears to be stripped out if it's defined in the version.cpp file of a static library and not referenced elsewhere.

Everything I've read basically says you either need to use linker flags to prevent symbol stripping entirely, which is probably an adoption-killer for this hack, or you need to use an explicit registration function called from the executable. I'd prefer to avoid this since it is just another thing a programmer could forget to update when a library dependency is added or removed.

My last idea, which I haven't tried yet, would be to put each version.cpp into a separate static library from the one it is describing. This version-only library could be linked without symbol stripping. I don't love this concept but it might work.

I haven't yet figured out how shared libraries can be worked into this framework at all. I'll worry about that after I get static libraries working.

View 5 Replies View Related

C/C++ :: Extracting Strings From Files

Feb 15, 2013

We have an assignment to produce code to gather a string of input from the user in which they are entering a date. We then have to extract parts of that string to make substrings, and display different formats for the date(I will add my code in here so you can see what I have done). It took me a long while plucking away at this to understand this part. You will see that at the end of my code I have opened a file months.txt. We were provided with a file which states months corresponding to dates. I.e. 01January 02February 03March 04April, and so on until December. Exactly how I have typed it is how it is in the file.

I understand how to open and extract what is in the file as a string. I have extracted this as a string called myMonth (as you can see in the code as well) NOW,

I am supposed to have the program search for the month in the file, matching that to the month the user has input earlier, and then use the number infront of that month. I understand the basics of using find(), and making substrings. But how on earth do you get the computer to correlate what the user has input for a month, to finding that in the file, and then using the correct number.

Here is the code I have done so far:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string myDate; // Date input from user;
string myMonth; // Input from months.txt

[Code] ....

View 1 Replies View Related

C# :: Send Multiple Files Over Tcp At The Same Time In C Sharp?

Nov 29, 2010

I have a tcp client - server implementation running in the same program, on different background worker threads. There will be instances of this program on multiple computers so they can send and receive files between each other. I can send files sequentially between computers using network stream, but how would I send multiple files at the same time from computer A to B.

Sending multiple files over one connection ( socket ) is fine, but having multiple network streams sending data to a client, the client doesn't know which chunk of data is apart of which file ?

View 3 Replies View Related

C++ :: Definition Of Const Strings In CPP Files

Mar 14, 2013

What is the best way to define const strings when there are separate header and source files?

For example, I have a header that only declare some enums. In that same header I would like to add string representations of those enums so that I can print them easily i.e string_representation[my_enum] for debug and error printing and so on.

If I define them in the header file, I will get a linker error for multiple definitions. If I remove the definition, then I can not define it in the source file.

View 13 Replies View Related

C :: Program To Match Strings From Input To Files Using Dfa

Sep 2, 2013

'Write a program to match the user input string with the contents of text files and give the result as to which files contain the input string. This has to be done by using finite automaton.' (Any language can be used) So basically, the user will input a string (in the command line or a gui) and "we must pass the text files to the DFA" (I'm double quoting this because it's precisely what my professor told) and then display those files which contain the string. The string can be hard-coded, ie,the user will get the output file that contains a specific string. ex: 'hello'. The problem is, I have never done any program on DFA so I'm at a loss. how to write the program. Should I read the files first and then use some 'switch' or 'goto' conditions for the DFA? Below is a code I found on the internet for simulating a DFA accepting a specific string.

Code:

s: accept = false; cin >> char;
if char = "m" goto m;
if char = EOF goto end;
goto s;
m: accept = false; cin >> char;
if char = "m" goto m;
if char = "a" goto a;
if char = EOF goto end;
goto s;
}

[code]....

View 3 Replies View Related

Visual C++ :: Saving Unicode Strings To Txt Files

Jan 20, 2014

In my project , we need to create an Array of Unicode Strings . The Array will contain 5000 Strings.

I need to write those strings to a text file which can be opened or edited with NotePad.

Normal _tfopen and fwrite are not able to create notepad compatible .txt file .. I mean the file I created is not readable with Notepad though file open mode is "w+t"

How can I save my unicode strings to a text file

View 6 Replies View Related

C :: Read Enormous Binary Files (10-100GB) And Parse Their Contents Bit At A Time

Dec 5, 2013

I am trying to read enormous binary files (10-100GB) and parse their contents a bit at a time. As part of the process I need to get the size of the file in bytes. The simple solution

Code: fseek(file,0,SEEK_END);
size=ftell(file);

fails because the file size overflows the long int type returned by ftell. I need a long long int.

Is there a reasonably efficient way to do this? The good news is that it only needs to be done once. I suppose I could read it one character at a time until I hit the end and keep count, but that just seems inelegant...

View 12 Replies View Related

C/C++ :: Round Robin Execution With Gantt Chart - Arrival Time And Burst Time

Mar 10, 2015

This is a round robin execution. with gantt chart. arrival time and burst time. I think there is an error in my formula to get the right answer,i cant resolve it but my program is running. What is the code or the right formula??

#include<stdio.h>
int main(){
int i,j=0,n,time,remain,flag=0,ts;
int sum_wait=0,sum_turnaround=0,at[10],bt[10],rt[10];
int ganttP[50],ganttStartTime[50];
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;

[Code] ....

View 2 Replies View Related

C++ :: CRC 32 Calculation Of File

Jan 3, 2014

i need to calculate crc32 of a input file and check with the original crc value of a file and return true/false,

View 4 Replies View Related

C :: Calculation Of A Bitwise Expression

Mar 6, 2015

I would like to ask about how we calculates the following bitwise expression.

Code:

unsigned char ch[2] = {0x49,0x49};
ch[0] | ch[1] << 8; I'm thinking ch[1] << 8 as 0x00 ...

So, I think that the above expression converts to 0x49 | 0x00 ... and the complete expression should be 0x49 for me.

But, the compiler gives me the result of 0x4949 as two bytes.How does the compiler calculate this expression as two bytes?show me the steps included in the calculation of this expression?

View 2 Replies View Related

C :: 2 User Inputs For Calculation

Apr 9, 2014

I want to have calculations take place inside a switch statement that calls the appropriate function. The menu portion of the program works well, but I can't figure out how to let the user actually input 2 different numbers to the functions. My questions are:

1. If I use scanf to assign values to the variables, what determines end of input to each variable? (ie.. scanf("%d%d", &a, &b) what is the end of a, what is the end of b?)

2. Should I assign the variables to user input inside the switch, or try to do it in the functions below?

3. Is there something I haven't thought to ask that will screw me over? I'm really new to this.

Code:
#include<stdio.h>
int add(int b, int a);
int mult(int b, int a);
main() {

[Code] ....

This really was a test of multilayer menu, but I want to add functionality if I can.

Changed a variable before posting and didn't change all the conditions testing it.

View 3 Replies View Related

C++ :: Simple Calculation Of Char?

Dec 17, 2013

void viewWasteReport(){
EXEC SQL BEGIN DECLARE SECTION;
char wasteid[5],wastetype[31],month[11],wastequantity[13],wasteweight[11];
//double wastequantity[13];
//double wasteweight[11];
EXEC SQL END DECLARE SECTION;
fnConnectDB();

[Code] ....

I want to obtain the the product of wastequantity*wasteweight, but i get error.

View 6 Replies View Related

C++ :: How To Do CRC Calculation For Base64 String

Aug 1, 2013

I am trying to calculate a CRC of a Base64 string.I give you the correct checksum : 2942042514...And now the string :

AQAAAAAAAABsYAAAAAAAAENvbXByZXNzZWRUaXRsZQB4nO0d2XIaSbI+hZ13
m0NCR0QNE7KOHcXKlkMwtnhyIIRkdjGwgGxpP35386jqursRsk0zQygkd+dR
lVmVmZVdl//3Xyl+E4/iixiJivgqBmIm5mIoJmIsfhW/iLp4LWrwbwUwY9EH
[code]....

I tried CRC 16, 32 and with polynomial 0xEDB88320L, and with all these tries, I cannot find the correct checksum, it is my main problem.I don't want C++ code source, but I am searching for the method or algorithm to find it. If you want to know, this string in base64 contains an string compressed in zip, which contains an UTF16 XML. I want to modify information, and modify Adobe Projet (prproj)

View 6 Replies View Related

C++ :: Inflation Calculation For Two Years?

Oct 1, 2014

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>

[Code]....

Write a program that outputs inflation rates for two successive years and whether the inflation is increasing or decreasing. Ask the user to input the current price of an item and its price one year and two years ago.

To calculate the inflation rate for a year, Uh, no, that’s wrong! To calculate the inflation rate for a year, subtract the price of the item ONE YEAR AGO from the price of the item for that year and then divide the result by the price a year ago. For example: 2014-Inflation-Rate = (2014-Price minus 2013-Price) / 2013-Price.

Your program must contain at least the following functions:

•a function to get the input
•a function to calculate the results
•a function to output the results

View 1 Replies View Related

C/C++ :: Do While Loop And Average Calculation

Dec 9, 2014

I need to create average calculating program using do while loop.

t = 1 - sin(x) when x > 0;
t = 1 + x when x = 0;
t = a + sin(x) when x < 0;
primary information:
x changes from 1 to -1 by step h = -0.5, a = -2

#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int main() {
int a = -2;

[Code] ....

How this program should look that's why this probably looks just like a mess.

View 2 Replies View Related

C/C++ :: How To Do CRC Calculation For Base64 String

Aug 1, 2013

I am trying to calculate a CRC of a Base64 string. I know the answer of the checksum, but I don't how to calculate it (It is for Adobe project).

I give you the correct checksum : 2942042514

And now the string :
AQAAAAAAAABsYAAAAAAAAENvbXByZXNzZWRUaXRsZQB4nO0d2XIaSbI+hZ13
m0NCR0QNE7KOHcXKlkMwtnhyIIRkdjGwgGxpP35386jqursRsk0zQygkd+dR
lVmVmZVdl//3Xyl+E4/iixiJivgqBmIm5mIoJmIsfhW/iLp4LWrwbwUwY9EH
+C1gx+KesH+IjjgTr4Bqj2h+Ey0hxRHQTMQNcHwSV/A0EYsA3oFSFlDngDAf

[Code] ....

I tried CRC 16, 32 and with polynomial 0xEDB88320L, and with all these tries, I cannot find the correct checksum, it is my main problem.

View 12 Replies View Related

C :: Simple Calculation - Function To Do Factorization

Feb 8, 2014

I wrote a function to do factorization (n!). while this function works perfectly:

Code:
int fact (double x){
register int z=1;
if (x==0)
return 1;
else
for(x;x;x--)
z*=x;
return z;
}

this doesn't:

Code:
int fact (double x){
if (x==0)
return 1;
else
for(x;x;x--)
x*=x;
return x;
}

what makes the second one different from the first one? can't see the difference..

View 1 Replies View Related







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