C++ :: Editing Certain Line In File?
Apr 16, 2013
Well,i hav a question requiring me to edit sales achieved by an employee for a particular month.
I'm having a dat.file which following format
Employee ID
Name
Sales(for a year)
For example
A00001
Harlem Shake
10.00 20.00 30.00 40.00 50.00 60.00 70.00 80.00 90.00 100.00 110.00 120.00
Wad I wanna is TO EDIT only the sales for July which is 70.00 to a new amount with other months remain intact.
I need to search particular id which will then link to their respective sales.
ofstream outFile;
string empID;
cout<<"Please Enter Employee ID:
[Code] ....
I tried to run myself before.But I could only create a new line instead of replacing.
To my understanding with ios::app ..will use the same file for editing..
View 4 Replies
ADVERTISEMENT
Jan 2, 2014
I have a problem editing a text file in c
Code:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
typedef struct
{
char *name;
float gpa;
[Code] ....
View 3 Replies
View Related
Dec 7, 2013
Basically what I am looking for is a way to get a block memory, copy it into ram in a format along the line of bit[#], replace the original with a new code that may or may not be the same size(they will be something to ensure does not try to save a fraction of a byte).
Is there an easy way to do this or do I just need to read work from a bin file?
View 3 Replies
View Related
Oct 30, 2014
I have a button that opens a file dialog box so that a user can pick a file. I only need it for the path and file name to be passed to another program. I do not want to open the file or care about its contents. I just want the name and path.
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
[Code].....
The problem is that as long as the program is running the file that the user picked is locked for editing. Adding the Dispose() had no affect. Multiselect and ReadOnlyChecked have no affect. Only closing the application frees the file.
View 7 Replies
View Related
Oct 19, 2014
I have a .dll file that is used by some kind of launcher. Now the .dll file has some kind of timer on it and after that set of time it wont let me use it, how i can edit that out of a .dll?
View 4 Replies
View Related
May 19, 2012
i have this program that i am undertaking.....this project needs to store customer details, edit them and delete them...now i am facing the problem of deriving a code to edit those details...
MY CODE
HTML Code:
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main () {
int choice [1];
string name;
[code].....
View 4 Replies
View Related
Nov 14, 2014
You are requested to create an inventory control application for a drink stall (give a name to the stall). The application is used to show the list of drinks the stall sells, how many of each item on‐hand and the cost of each item. The records are to be saved and retrieved to/from a binary file called “drinks.txt”. For each drink in the stall, your program is to keep the information as a Record Structure called DrinkRecord. The structure should at least consist of the following:
(1) Item Number
(2) Item Name
(3) Quantity
(4) Unit Price
Your application should have the following features:
(a) Display a drink information
(b) Add a new drink information
(c) Update a new drink information
(d) Delete a drink information
(e) Display all drink information
#include <string>
#include <fstream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
[code].....
Everything works fine with minor issues, but I'm having trouble with the editing function. I need to be able to search for a specific drink then be able to edit its contents and print the new contents to the file. I have not created a structure yet. I will do that as soon as possible.
View 1 Replies
View Related
Aug 17, 2014
I am trying to read a file line by line and then do something with the informations, so my method looks like this:
Code:
void open_file(char *link) {
FILE *file = fopen(link, "r");
if (file == NULL) {
fprintf(stderr, "Could not open file.
");
exit(EXIT_FAILURE);
[Code] ....
1) The first complain of valgrind is at the line where I use fgets and its telling me (invalid write of size x), but I have allocated my line to 56000 and the read line is shorter, why is there a write size error then :S?
2) at the line where I realloc where I try to shrink the space he's telling me: Address .... is 0 bytes inside a block of size 56000, But I know i need only this space so why is there a write over space error :S??
View 9 Replies
View Related
Sep 25, 2013
So I'm reading a file line by line and storing it backwards into a list. So if the file has has this format...
1
2
3
4
The code should store each line in a list as such...
4, 3, 2 ,1
Instead the code will store the last variable in all nodes. So the final list will look like this...
4, 4, 4, 4
Here is my code...
struct node *head = NULL;
int i;
while(read(in, &i, sizeof(int)) != 0) {
struct node *temp = malloc(sizeof(*temp));
temp->line = &i;
temp->next = head;
head = temp;
}
View 4 Replies
View Related
Jul 15, 2013
I need to read lines from one file and copy them line by line into another file using dynamic memory allocation. It compiles but gives me a seg fault. Why/How?
Code:
int main(){
FILE *fp1;
FILE *fp2;
FILE *i;
fp1=fopen("file1","r");
fp2=fopen("file3","w+");
[Code] ....
View 2 Replies
View Related
Jul 5, 2013
I have a text file (test.txt) with the following data:
01,05,25,20130728
01,06,25,20130728
01,07,25,20130728
01,08,25,20130728
01,05,25,20130728
01,05,25,20130728
01,05,45,20130728
01,05,65,20130728
01,05,85,20130728
01,05,35,20130728
01,05,25,20130728
01,05,35,20130728
I want to read this to one string called line. So far I have this code:
string line;
ifstream myfile ("/home/Test.txt");
if (myfile.is_open()) {
while (myfile.good()) {
getline (myfile, line);
for (int a = 0; a <= 335; a++) {
cout <<line.at(a);
} }
myfile.close();
}
so far its only printing the first line and then throwing an instance of 'std::out_of_range'
View 2 Replies
View Related
Oct 5, 2013
I need to read a text file which has various lines containing integers. I need to write those integers separately in a vector. Example, the first line of the text file contains 3 9 8 7 6 so vector[4]=3, vector[3]=9, vector[2]=8 and so on. Next read the second line 4 1 2 3 4 5 and write to another vector vector[5]=4, vector[4]=1...
I tried the code below but it will write from the second line, the whole line in one vector index.
int str; // Temp string to
cout << "Read from a file!" << endl;
ifstream fin("functions.txt"); // Open it up!
string line;
// read line count from file; assuming it's the first line
getline( fin, line );
[Code]...
View 1 Replies
View Related
Apr 12, 2015
Im trying to read from a file, line by line, with no specified number of values in the file. Check out my code:
int main() {
string x;
ifstream fin;
int count = 0;
char ch;
fin.open("CWC_Master.txt");
if(!fin)
[Code] .....
Now, this works great! However, its skipping some lines. And I dont know why. For example: Lets say that the input file is:
superman toy
sm2335
19.99
batman toy
bm5532
25.99
aquaman toy
am6786
26.00
Where it should output the above, instead it outputs every other one. Like:
superman toy
19.99
batman toy
25.99
aquaman toy
26.00
How can I fix my code so that it SIMPLY(i say simply because I am still a beginner coder) can read line by line?
View 7 Replies
View Related
Aug 24, 2013
I can able to get the last line ten chars but i cant get if the last line is null.
here is my code
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
[Code] ....
here with i have enclosed my file where i am pick my last ten chars ...
Attached Files : log.txt (4.8 KB)
View 1 Replies
View Related
May 12, 2014
I have to read the information about logic gates from a file. The file format is shown below:
Code:
gateOne = NAND(inpA, inpB)
gate2=NAND(1,2)
3 = NAND(23,25,26)
As, it can be seen from the above structure that whitespaces are not same everytime. So, to deal with this situation, i am using boost library to remove all whitespaces from the line which is being read and then try to find the name of gate and its input. My code is given below which is able to correctly find the gate names and its first input...but my code is not able to find the second, third and so on input names.
Code:
//C
#include <stdio.h>
//C++
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <boost/algorithm/string/erase.hpp>
[Code] ....
View 3 Replies
View Related
Oct 13, 2014
How to read a file line by line and then later access them by doing something like
Code:
lines[0] //Line number one
...
lines[100] //Line number one hundred and one
lines[100][0] //L
lines[100][1] //i
lines[100][2] //n
lines[100][3] //e
lines[100][4] //
lines[100][5] //n
...
View 13 Replies
View Related
Jul 2, 2013
I have an external file with one column of data. If I have a counter value let say counter =1, and counter++ and so on. How I can write such a c++ code that if the value of counter and value from the external file are same then generate an action let say cout both values i.e. value of counter and value from external file.
for more information, here is an example:
data in file(in one column): 2 6 8 9 10...
value of counter : 1 2 3 4 5 6 7 8 9...
then cout values only if value of counter and value from the file is same.
Here is my code so far, but it does not seem to work;
#include<iostream>
#include<fstream>
using namespace std;
int main() {
const int SIZE = 10; //Size declaration of array
int hours[SIZE]; //Array declaration
[Code]...
View 12 Replies
View Related
Jan 23, 2015
I am reading my file (20GB) line by line using boost like this
PHP Code:
boost::interprocess::file_mapping* fm = new boost::interprocess::file_mapping("E:Mountain.7z", boost::interprocess::read_only);
boost::interprocess::mapped_region* mr = new boost::interprocess::mapped_region(*fm, boost::interprocess::read_only);
char* bytes = static_cast<char*>(mr->get_address());
An exception is thrown in the second line while allocating memory for mr.
I use boost because it can also work in Mac which my code will be ported to.
View 3 Replies
View Related
Jul 27, 2013
First of all I need to know how to read from file.
Second, I need to read line by line from the file.
For example, the file contains:
8H 3S TH 9D 5S
5D KD 9H 4D 3D
8C TD 5D QS 2C
I wanna use array, so I need to store 8H in array[0], 3S in array[1], until 5S get stored in array[4].
I need to read the first line, the the second, and then the third.
View 3 Replies
View Related
Mar 10, 2014
I'm trying to edit an image by multiplying the red component of each pixel by 10 and leaving the other components (green and blue) untouched. I'm not really sure how I'm supposed to edit the pixels one by one. I have this so far. I think there is something wrong with my ppm header as well. Is there a way to make a ppm header without specifying the bounds so that it conforms to the image you are putting in?
Code:
#include <stdlib.h>
#include <stdio.h>
#define PICTURE_FILE 1
#define MIN_ARGS 2
#define h 768
#define w 1024
void solve(FILE *in_picture, FILE *out_picture)
[Code] .....
View 6 Replies
View Related
Sep 11, 2014
I have this function that takes the collision location from an object then creates a new object for particle effects.
This is one of the functions that is called when creating the particle,void Particles_Create(i32 iID, Vec3 &vecPos, i32 ProjectileType, i32 iNumberOfParticles, float fSpread, float fGrowSpeed, float fMaxSpeed, float fMaxSize, float fParticleTime);
I want to be able to change the "Vec3 &vecPos" variable, when I define the variable that goes into the function I've defined it as: "Vec3 vecPos;" if I define it as "Vec3 vecPos(float fvx,float fvy,float fvz);" the variable cant be fed into the function.
I cant change my function because its used elsewhere but I want to be able to change the x,y and z elements inside the Vec3 vecPos variable. How without redefining it as Vec3 vecPos(float fvx,float fvy,float fvz);
View 10 Replies
View Related
Sep 6, 2014
I have tried googling, so, reddit, irc, and various other forums. Anyways, I am writing a todo list app in c. It generates an xml tree that looks something like this: [URL]... . The problem where I am struggling, is in the function todo_complete, I try to make the attribute of an item switch from false to true. it does it without error, but I can't make it stay that way. here is the code: [URL]...
View 3 Replies
View Related
Mar 4, 2014
I have a char correctAns[100] which is empty when initialized. i want to make it hold a different string for each section, so i can use strcmp to compare the correctAns to the answer given by user. here is code
#include <stdio.h>
#include <string.h>
int main() {
char answer[100];
int checkAns;
char correctAns[100] , incorrectAns[100];
[Code] .....
View 1 Replies
View Related
Dec 6, 2014
I'm trying to create a program for my wife to be able to browser through and edit folders and specifically word documents- really just a shiny organization tool without having to open up Word. I'll be integrating other functions into this program but Word is what I'm worried about.
At the moment I've been able to create a file browser with the ability to add and remove files within the main directory of the program. Basically just C:Users\%user%mainDirdata*
Within the data folder I have the main folders which will be displayed as tabs across the top and then any subfolders of the main folders will be displayed on the left side after you click on the main tab.
[URL]
I'd need the toolbars to be integrated into the program across the top and then a window that changes depending on the document selected on the left side based on the content of the word document located in that folder. I haven't been able to find anything online and I'm not really able to spend $800 on the alternates that look like they just do automation as well.
View 10 Replies
View Related
Feb 25, 2014
I am trying to write a program that will read the id3v1 tag of an mp3 file, output the current information, and then allow the user to edit the ID3 tag. I can get it to output the information but I'm having some issues getting it to edit correctly. It seems to try to edit the wrong fields.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
int end;
ifstream myInputFile;
myInputFile.open("01-Cheeseburger in Paradise.mp3", ios::in);
[Code] ....
View 8 Replies
View Related
Jul 10, 2013
Basically I have an tile class with the following variables: x, y, texture, and solid. I have created an array called tile MAP[map_tiles_x][map_tiles_y]. The object of the following snip-it of code is to loop through all of the tiles in the map placing their default values in each. For some reason this code does not work as planned, but in theory shouldn't it? I cannot see why it doesn't work. (BTW I do plan on open sourcing this map editor.
void init_map(){
for (int tile_y; tile_y < map_tiles_y; tile_y++){
for (int tile_x; tile_x < map_tiles_x; tile_x++){
MAP[tile_x][tile_y].x = tile_x * tile_size;
MAP[tile_x][tile_y].y = tile_y * tile_size;
MAP[tile_x][tile_y].solid = false;
std::cout << MAP[tile_x][tile_y].x << ", " << MAP[tile_x][tile_y].y;
} }
I should also add the effect of the code. Basically it only sets the default coordinates for the first object :/.
View 4 Replies
View Related