I am working on a project which is a fairly simply BAC calculator. I am attempting to grab data from a text file, which contains state abbreviation, maximum BAC before aggravated, and minimum license suspension. The text file looks like
I am currently trying to read in a file that takes in the input in the following form.
Code: HANK>25 BOB>31 AL>54 BILL>41 ABE>63 JEFF>50
I have tried the following solution:
Code: #include<ifstream> #include<iostream> using namespace std; struct node { string name; int age; ); int main () {
[code]....
The problem is a.name, it's extracting the entire string before the space character causing p.age to contain "BOB" and so on. I've tried using p.get(p.name, sizeof(p.name), '-') with '-' as the delimiter and p.getline() using a character array instead of a string. How would it be possible to only copy the string into a.name before the '>' character?
#include <iostream> #include <string> #include <istream> #include <sstream> using namespace std; int main() { string groups[3] = {};
[Code] ....
It outputs jibberish. I can do what I need to do but I would need to declare more variables and write more cout's, isn't there a way to add these elements to a stringstream or streambuffer? My goal is to write this program and make it as comprehensive as possible but also with very few lines.
(I'm not sure why I used an intermediate string; it's pretty much legacy-code at this point, which I just reuse every time. Still works, so why change it!)
The problem is I'm using two types of data sets now, and the difference is one (optional). Most data files just have an arbitrarily large number if the second must be ignored, but others have nothing.
In the normal case, I'd simply use sline >> d >> L; to extract the parameter values. However, I'm not sure how this line will behave if the second parameter is omitted. Will it read nonsense? How do I check whether or not the parameter was set or not?
I wrote a program to write text contents to file stream through fputs, the file stream address was changed in the middle of writing text content to the stream (11% text content have been put into the file stream), that cause the file stream pointer can be evaluated problem and raise exception on stream validation code in fputs library function, my question is what things could go wrong to make file stream pointer changed its address to something else or a NULL pointer if the file stream have not been flushed and closed.
I am working on a project were I have to read line form ( PLC ) programmable logic controller generated text file with lines like this
Circuit Value Current 2.33 4.32 5.55 there could be up to 3000 lines per txt file
I am using string stream to parse the line, for the sake of good programming I which to check weather first three values are string and last three values are actually floats raise or throw an exception if they are not ....
Issue 1: I am using a stringstream object in a block of my program that needs to be visited repeatedly depending on a user's selection from a menu. I want the contents of this stringstream object to be cleared any time control gets to this part of the program. I have tried the clear and flush functions to no avail.
Issue 2: I am reading data from a source text file that would be regularly changed during the course of program run. After the program run is over, I am supposed to save the results(which is basically the source text file AND all updates) in a destination file. This destination file would then serve as the source file when next the program is run. In other words, I want a scenario where my results overwrite the original contents of the source file; implying that my source and destination files are now one, pretty much. How can I do this?
I was going over this with a friend and it seems as though getline() is not reading anything in and thus throwing the abort error. I'm not sure why this is because I've included the textfile, with the correct name of course, in both the regular file location and the debug folder. I ask for user input and the user then inputs the name of the file they want, I do some required things behind the scenes and display the results for them in a cmd window. I've included pastebin files for both my header and cpp files because it is far to large for one post I shall, however, post the full code in the comments.
Quick Code
The problem occurs on line 159. I'm assuming once this line is fixed, line 163 will have the same problem.
// Read regular price getline(nameFile, input, '$'); vectorList[count].regPrice = stof(input.c_str());// Casts string to a float // Read sale price getline(nameFile, input, '#'); vectorList[count].salePrice = stof(input.c_str());
I am working on an assignment to create a Complex number calculator. In this assignment I am to ask the user for input to the calculator. We are given a sample run output that looks like this.
Enter operand1: 3 4 operand1: (3, 4) Enter operation : + Enter operand2: 1 2 (3, 4) + (1, 2) = (4, 6)
My question is how would I take from the user: an integer followed by a space followed by another integer and convert that into two seperate accessible int values that I can save as real and imaginary values.
I have a calculator with buttons, and when I click the numbers or operators, it goes to a string array. So;
Press 3 Press + Press 2 Press =
and my array is str[0]='3' str[1]=.... so on...
And also I have a C code which calculates the string you entered with some algorhytms and gives a double value as a result. So the question is;
How can I send my STR array in C# to my C program? I mean I want to use my C program as a source code. and How to return that double value to my C# program?
For now, I don't want to change my C codes into C# codes. I want it to keep as is. Just use it as a source code. Is that possible?
I should state that I am recently new to C programming. I have dabbled with Python in the past, but nothing formal. I am taking a C programming class, but it is an introductory course. As such, the instructor is moving extremely slow through the material.
With this program, I am trying to search a given text file (line-by-line) for user-submitted data. I then want to be able to store which line that data was found on. The program runs, but it always results in "Sorry, couldn't find a match." Even if it shouldn't.
I should probably explain my overall goal with this program.I would like to write a program that will calculate the molecular weight of a compound. I expect the user entered molecular compound to be something like this: CH3COOH (An equivalent entry could be C2H4O2)Also, it needs to be case sensitive because the chemical formulas are case sensitive.
The output will be "The molecular weight of CH3COOH is xxx.xxxxx grams".I have two text files as well. One contains a list of all chemical symbols, and the second is a list of all atomic weights in the same order as the first. I want to place the user inputted data into an array, then search for each element of that array in the chemical symbol text file. It will show which line it was found on, then I can use that line to grab the atomic weight from the second text file.
i have a work to do that consists on a given char pointer to a chain and a also given char pointer to a string. i have to search that chain in the string, and return the position where the beginning of the two it's equal. but only if they are equal.
example: string is "abcd" and the chain is "bc". want to find the chain, and if it exists, the position return will be 2. in the work it says that we should use sprintf() too. here is my code, which is incomplet yet.
Code:
char* pos(char* C,char* S){ char *str = S; char *chain = C; int i, j, temp; int lengthStr = strlength(C); int lengthChain = strlength(S); }
[code]....
my doubt is how to use sprintf() and where. if i have to use malloc() and free(),
I'm trying to use the biSearch function to search for a keyword in the dictionary.
Code: int biSearch(Dict DictEntries[MAXENTRIES],int start, int finish,char *keyword) { int mid = (start+finish)/2; int index = strcmp(DictEntries[mid].key,keyword); printf("%s=%s ",DictEntries[mid].key,keyword);
I am a beginner of c#.. i have try to made a windows notepad and face some issues. I want to add find string from open file... and also want to replace it with a new string... Is there any simple and easy solution to this problem??
#include<stdio.h> #include<string.h> #define MAX 25 int main(void) { int ch;
[Code]....
i think that cause this program to be error.because when i using the reference from internet, the program was executed for sure.This code what i mean
Code: #include <stdio.h> #include <string.h> #define MAX 10 int main () { int ch; char str[] ="This is a simple string"; char str1[MAX]; char str2[MAX];
[Code]....
and rather than that i didnt have anymore idea to make that replacing string.
So basically here I have a menu in my C program and if I were to select option 2, I would enter a string up to 30 characters and it would output each block of 16 bytes should be shown which contains a character in the requested string. However, when I compile and run the program and search for the string, nothing happens. what I may be doing wrong?
Code:
else if (select == 2){ printf("Enter a string of up to 30 characters: "); scanf("%s", &userstr); //Compares both user's string and file string for (i = 0; i < size; i++){ if (strcmp (buffer, userstr) !=0){
I need to search for a string in an array of objects, this is what I have but it does not seem to work, it always gives me the second string in the array instead of the one that i search for.
void binarySearch(Student S[], string name) { int first = 0; int last = 9; int middle; int position = -1; bool found = false;
I currently have a file which allows inputs to record different transistor types. I then have the task of accessing this structure, find a certain manufacturer ID, and print the information about this particular transistor.
My problem is accessing the array to search through.
Here is my code:
Code: #include "stdio.h" const int IDLEN=30; //All constant values defined const int POLARITYLEN=3; const int MAXSTOCKITEMS=10; //First structure defined struct TransistorRec {
[Code]......
The errors I am currently getting are on line 54 'expected primary-expression before "struct"' and on line 60 ' 'maunfacturersID' undeclared'
I need it to search a dynamic array which I build from an input file. When it finds the user-input string, I want it to store the line number, and continue searching, and record all lines that contain the user-input string.
Here is a link to my complete main.cpp, header file, and implementation file. The function I am having trouble with is "Bagger::lineSearch"
I'm having a problem when i convert from fraction to string. When I run my program it runs fine I'm supposed to get an output of the fraction ex (2/5) and the decimal 0.4 the problem is that it does not output the fraction all I get it / and 0.4
the code for converting from fraction to string is the following std::string string; char numerator[100]/* = {0}*/; char denominator[100]/* = {0}*/; _itoa_s(numerator_, numerator, 10); _itoa_s(denominator_, denominator, 10);
I am trying to implement a Task scheduler where i have n number of tasks. The Idea behind my task scheduler is that in a loop of queues of a vector, task should get enqueued to the shortest queue among the loop of queues, which is done by the following code.
#include <vector> #include <queue> std::vector<std::queue<int> > q int min_index = 0; task t // implemented in the other part of the program
[Code] ....
Next i am trying to extend this paradigm to reduce the overhead time of the scheduler, Instead of searching the shortest queue every time, search after some condition ie. search the shortest queue after 5 tasks gets enqueued to the shortest queue.
i need to do something like this
#include <vector> #include <queue> std::vector<std::queue<int> > q task t // implemented in the other part of the program while(q[min_index].size()!=q[min_index].size()+5) // check whether current min_index queue's size is increased 5 more times if not goto enqueue