C/C++ :: Deleting Certain Lines In Txt File?

Dec 27, 2013

I was assigned to modify Game Lobby code. All the data can be saved in txt file and can be displayed when running the code..How can i remove or delete the certain lines of a txt file when running the cmd?.. I cant program it to be able to delete certain lines but i manage to program to delete the entire data, which is not what i want..

Here's the code so far...

#include <iostream>
#include <fstream>
#include<vector>
#include<cstdio>
#include<iomanip>
#include <string>
using namespace std;
class Player {
public:
Player(const string& name = ""): m_Name(name), m_pNext(0) {}

[Code] ....

View 3 Replies


ADVERTISEMENT

C++ :: Deleting Repeated Lines In A Text File

Jul 30, 2014

I have a text file with repeated lines, and i would like to get rid of the duplicate information, an algorithm to achieve this?

Example of my text file (the actual file may be huge, up to 500MB):

+Hello
+Bye
*The sun
-The moon
+Bye
/One coin
+Bye
+Bye
+Hello
*The sun

And i would expect to get something like this:

+Hello
+Bye
*The sun
-The moon
/One coin

I know how to open and read a file with fstream and getline(), but i don't know how to make the comparison.

View 6 Replies View Related

C++ :: Algorithm For Deleting Lines In Tetris?

Oct 9, 2014

I'm making tetris but didn't go the conventional way of using matrices to hold binary id's of my shapes. I thought it would be easier that way, but now I'm stuck on deleting complete lines of blocks. Here is my code that checks for complete lines:

bool lineComplete = true;
std::vector<sf::FloatRect> lineTest;
sf::RectangleShape rect;
rect.setSize(sf::Vector2f(1, 1));

[Code] .....

Now in RemoveLine(), I need to access the individual blocks of each gamePiece. Each gamePiece has a vector of sf::RectangleShapes (SFML), which represent one block of that tetromino:

std::vector<sf::RectangleShape> pieceRectangles_; the sf::RectangleShapes are stored like so:
case 0:
//line
for(int i = 0; i < 4; i++){
sf::RectangleShape rect(sf::Vector2f(10, 10));
rect.setPosition(origin.position.x + (i * 10), origin.position.y);
rect.setTexture(&imgr.tetrominoTexture);
rect.setFillColor(sf::Color(243, 16, 16));
pieceRectangles_.push_back(rect);
}

My question is how do I got about accessing particular sf::RectangleShapes stored in this vector if that sf::RectangleShape is located on a complete line that is being deleted? Would I need to create a Block class and give it members that hold each block's location?

View 1 Replies View Related

C :: Self Deleting Of EXE File By Program Itself

Sep 10, 2014

How to do self deleting of exe file when it is run'd.

View 2 Replies View Related

C++ :: Deleting Records From TXT File

May 8, 2014

Is this the right codes for deleting a recoed on the text file.

void dlte(){
string line, recorddate;
cout << "Please Enter the date of record you want to delete: ";
cin >> recorddate;
ifstream myfile;
ofstream temp;
myfile.open("herald.txt");

[Code] .....

View 1 Replies View Related

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++ :: Error In Deleting And Renaming A File In C

Jun 19, 2013

Here is my code i wrote for storing details of my apps.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct app {
int id;
char name[200];

[Code] ....

View 1 Replies View Related

C++ :: Deleting Certain Bytes From Binary File?

May 26, 2013

How to delete certain bytes from middle of a binary file?

Those bytes are in fact of a struct.

One approach I found was to re-write the whole data except the struct I want to delete. But may be its not good one if file size is in gb and I will have to write complete data again.

View 1 Replies View Related

C :: Reading Matching Strings From A File And Deleting From Another

Sep 26, 2014

We are generating emails for freshman students, however, the system probably due to server overload fails to generate some emails. So I'm working on this c code( probably was a wrong choice) to search for regexp matching the generated emails and deleting from the list of students and propective emails.

I"m currently at the stage of making sure the code can find all the matching regexp from the student list file before deleting! But the code fails to read all matching regexp?

Code:
//Filename: SearchReplace.c
//Usage: This searches for lines in a file containing a particular work and deletes the lines.
//Licence: GNU P.L.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

[code] .....

What I'm missing. It recognizes some regexp and fails to recognise some. Been staring for hours!

View 4 Replies View Related

C :: Array Of Structs (adding / Deleting Elements To A File)

Sep 20, 2013

I want to write a program to record my neighborhoods's name and address by using an array of structs and file.

my array of structs is

Code:
#define SIZE 30
typedef struct{
char name[30];
char address[100];
}Detail;
Detail neighbor[SIZE];

And I want to make adding,deleting, and searching functions.Something like

Code:

void add();//Add name and address to a file,
//and add more to the same file if I want to.
void del();//Delete or Change some neighbor's name or address
//in the same file(Can I?)
void search();//Search name and show detail

So I started to code adding function first, but I don't know that I need to use pointer to code each functions relations, and I don't know how to check that my input's already exists yet. But I started some code below...

Code:
void add() {
int i=0;
FILE *fp = fopen("neighborhood.txt", "at");
if ( fp != NULL ) {
do{

[Code]......

View 8 Replies View Related

C# :: Mapped Network Drive - Deleting Or Moving A File

Sep 16, 2014

Currently I'm trying to do something extremely basic: delete or move a file

I have a mapped network drive (Y) where I have a file I need to move from one folder to another

First was doing the obvious:

System.IO.File.Move("Y:TempFile.txt", "Y:Temp2File.txt");

Not much to go wrong here, right? As long as I have the correct permission to write in the folders and the folders exists, this would normally go smooth. But for some reason it only copies the file. The source file still exists, but it has successfully copied the file to the destination folder. No exceptions has been thrown or anything... but the file still exists in the source directory

I then changed the code to the following:

System.IO.File.Copy("Y:TempFile.txt", "Y:Temp2File.txt");
System.IO.File.Delete("Y:TempFile.txt");
Console.WriteLine("See mommy, no Exceptions");

As expected the file copies correctly, but the delete command is completely ignored. The file is not deleted, but the Console.WriteLine command is called

I'm running the application as the logged in user. The user has permission to delete the file. If I try from Windows Explorer, the file is correctly deleted. Unfortunately my application refuses to delete the file and even worse, it will not even throw an Exception.

View 10 Replies View Related

C :: Erase From TXT File Lines That Contain One Name?

Feb 4, 2013

Well, I have a .txt file that contains, together with a few characters, columns of values that I want to save in different files like is written in the program (file 1, file2, file3 - a with x, b with y, c with z). BUT, I don't want the values from the lines with the saying "interpolated_vector" to be printed in any of the three files.

What I have is the code below, that has the code that creates the three new files with the columns of values that I want. It is working fine!

Code:

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
int i, count;
double *a, *b, *c;
double *x, *y, *z;
char tag[5][255];

[Code]...

I've tried and tried, but couldn't make it work properly. I could only erase one line with "interpolated_vector" using fgets, but all the other lines below this were printed into the three new files (file1, file2, file3).

View 5 Replies View Related

C++ :: Counting Lines From A File

Apr 23, 2013

How I would go about counting lines from a file at the same time as extracting words? I need to know the line number to output what line the word is misspelled on. I tried getline and using sstreams but I could not get it to work.

void SpellCheck::checkValidWords(const string& inFileName) {
string eachword;
ifstream istream;
istream.open( inFileName.c_str() );
if ( !istream.is_open() ) {

[Code] .....

View 3 Replies View Related

C++ :: Reading From Specified Lines In File?

Jul 13, 2013

i want to read text between two indices in the file using file i/o operations in c++. HOw can i do it? for example, here is the text file:

1:
..
..
2:
..
..
3:
..
..
4:

in this text file i need to print only the lines between 2: and 3:. How could this be done?

View 1 Replies View Related

C++ :: Read Only Certain Lines From CSV File

Oct 21, 2014

I am trying to read lines from a CSV file and put the values into vectors. The CSV contains a large amount of data and I would like the program to only read certain lines from the CSV into the vectors. An example of the data is below. In my code the user inputs a secid. I would then like the code to only read lines from the csv where the secid matches what the user inputs. The secid's are also not in order so I can't just use a while loop.

My current code is below the data.

secideffect_datecusip ticker
10131014MAY19972313510 AMZN
10131008MAY19982313510 AMZN
10131028NOV20002313510 AMZN
10131023JUL20012313510 AMZN
10196601JAN199663858510 NB
10196601OCT199806605F10 BAC

ifstream infile3("filepath.csv");
if (!infile3) {
cerr << "Couldn't open file!"<<endl;
return 1;

[Code] .....

View 1 Replies View Related

C++ :: Read Certain Lines From A File?

Aug 22, 2014

I want to read certain lines from a file. Let say if the line contains word "makes", the line will be loaded on the screen.how to modify this code.

// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;

[Code] ....

View 1 Replies View Related

C :: How To Count Lines In Dat File Using Fscanf

Sep 15, 2013

I need a way to count lines in a .dat file using fscanf. I must use a regex to check that the characters in the file are alphanumeric. In essence I need to count the ' ' character. I know fscanf ignores this character. I need to exit if it detects anything other than alphanumeric with the digit that is "problem" along with the line number. My .dat file is:

Code:
howard jim dave
joe
(
Maggie My fileCheck.c is: Code: #include "main.h"
int fileCheck(FILE *fp)
{
int ret_val;
int line_count = 0;
char file[BUFF];

[Code]...

The output I am getting is:

Code:
file opened Digit: ( is not an alphanumeric character on line: 5 Program will exit! File closed As you can see, the character "(" is not on the 5th line but the 3rd. It is the 5th "string."

I also wanted to show the regex I am using.

Code:
#define to_find "^[a-zA-Z0-9]+$"

How this can be accomplished?

View 5 Replies View Related

C :: Counting Number Of Lines In A File

Feb 2, 2015

it looks like a popular method for determining the total lines in a file is to read the entire file character by character in search of ' '. I have a file with 5 lines, but for some reason this code isn't finding any instances of ' '. Is this possible? Is there a better way to get the number of lines in a file?

The file looks like this:

Code:
NAME: John
FRIEND 1: Steve
FRIEND 2: Andrea
FRIEND 3: Ken
OCCUPATION: Programmer

Code:
FILE *f = fopen(currentFile, "r");
if (f == NULL) perror ("Error opening file.
");
int ch, lines = 0;
while(!feof(f)){

[Code] .....

View 2 Replies View Related

C++ :: Reading Lines From Text File

Jun 3, 2014

I am trying to read lines from a .txt file like this:

// "file.txt"
This is the first line.
This is the second line.

To do this, I tried using the following code:

int main() {
std::ifstream data;
data.open("file.txt");

[Code] ....

The output I want is:

This is the first line.
This is the second line.

However, all I am getting is:

This is the first line.

I can't quite see why this isn't working. I am decently familiar with file streams in C++, so I thought I would know what I was doing, but apparently not.

View 1 Replies View Related

C++ ::  Loading File With Multiple Lines

May 17, 2014

I'm trying to load a file that look like this:

IP:123.123.123.123
Port:12345

I can't figure out how to load multiple lines. I tried using , but I can't get it to work. Is there a better way of doing it than I am right now? This is my code.

char message[100];
int messageCount = 0;
for(unsigned int i = 0; i < file.size(); ++i) {
message[i] = file[i];

[Code] ....

View 1 Replies View Related

C++ :: Attempting To Get Data From Lines In A File?

Mar 30, 2014

For a project we are given a file with a couple of thousand lines of values, each line having 9 different numbers.

I want to create a for/while loop that, for each loop, stores the 8th and 9th integer of a line as a variable so that I can do some calculations with them. The loop would then move onto the next line, store the 8th and 9th numbers of that line as the same variable, so that I can do the same calculation to it, ending when I've run out of lines.

My problem is less to do with reading the file, I'm just confused how I'd tell it to take only the 8th and 9th value from each line.

View 5 Replies View Related

C++ :: Read And Rewrite Lines In File

Jan 2, 2015

My task is to write a function for borrowing books form library called borrow(name,surname, student_id, book_id), which will connect information of borrowed book's ID and student's information in the file.

File looks like this:

John Jackson 45 0
Michael Gregory 34 56
Ann Cawitch 23 0
Chris Lamb 34 50
...

First two words are name and surname of students. First number represents student's ID and second one represents ID of book. If ID of book is 0, it means that student hasn't borrowed book yet, so he can borrow some book. If ID of book is not 0, it means that student can't borrow a book until he returns the old one. So, when student borrows book, ID of book in file should change from zero to some number

This is my code:

void borrow(string name, string surname, int student_id,int book_id ) {
string a;
string b;
int c=0;
int d;
fstream f2;
f2.open("students.txt", ios::out |ios::in);

[Code] ....

Whenever I call function (for example borrow(John, Jackson,45,15)), I get answer "Student isn't sign up library."

Am I on a right path? How to make this code to work?

View 4 Replies View Related

C++ :: Reading Lines From A File Into Array?

Sep 1, 2014

The first part of the exercise is to read the lines from a file placing each line into an array. I thought my code looked correct however nothing but garbage prints out. Here's my code.

#include <iostream>
#include <fstream>
#include <string>

[Code]...

View 2 Replies View Related

C/C++ :: Writing Repeated Lines To A File?

Aug 26, 2014

I am working on a problem for the CS50 online course through the Harvard web site. I am trying to re-size a bmp image. They gave us a small program that copies a bmp image and we are to modify it to re-size the image. Here is the page [URL]..... Any way I am trying to move the file position indicator backwards so I can read the same line from the input file. So I can resize the file vertically I have the image resized horizontally but it keeps over writing the same lines vertically.

/**
* bmp.h
*
* Computer Science 50
* Problem Set 5

[Code]...

View 4 Replies View Related

C++ :: Counting The Number Of Lines In A File?

Jun 3, 2013

I was trying to make a function that would return how many lines are in a certain file. I was looking at [URL] which talks about how to count how many characters are in a text file. I just want the number of lines with in a file.

View 2 Replies View Related

C :: Program That Deletes Same Lines In A Text File

Mar 23, 2013

I am working on a program that deletes same lines in a text file. I already wrote it, but it still doesn't work.

Code:
#include <stdio.h>
main(){
FILE *f1,*f2;
char oneword[100],filename[25];
int c;
long int i,j;
char *norstring[500000]; /* I count from 1 */

[Code] ....

View 3 Replies View Related







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