C++ :: Program To Delete The Sixth Line From A File

Nov 18, 2013

How to use these functions: fread, fclose, fseek, ect.

Q1) Write a program to delete the sixth line in a file. Do not change the sixth line to a blank line; delete it completely.

*** this one I was able to replace the file with what I wanted but realized it needs to be deleted ***

Q2) Write a function that deletes the last line of any file.

*** this one didn't even know where to start ***

View 3 Replies


ADVERTISEMENT

C/C++ :: Delete Specific Line In Text File Using Program?

Feb 6, 2014

Some codes to delete a text in a specific line in a text file.

Example:
This is line 1
This is line 2
this is line 3

Removing line 2,

This is line 1

This is line 3
//////////////////

View 2 Replies View Related

C/C++ :: Delete A Line From A File?

Oct 19, 2014

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

[Code]....

assume here the list that i output alice wonderland,8563 capitain jack,842 john carpenter,753leisely chow,421 how do i delete "john carpenter, 753" and rearrange my list in the file like alice wonderland,8563 capitain jack,842 leisely chow,421 i have read about remove function, but it only removes the hole file, but i want to keep the file only modify the lists in the file

View 14 Replies View Related

C++ :: Delete A Line From A Text File

Jun 7, 2013

How can i delete a line from a file created using a C++ program?Can i get a code sample.

View 1 Replies View Related

C++ ::  How To Delete A Line In A Text File

Jan 29, 2015

The program i wrote can run but did not work. I want to delete a line from the textfile "StaffList.txt" but when i cin the name, for example "Ben". After the program ran finished and i open the textfile, the name "Ben" and the whole line is still inside the textfile! I have created the "temp.txt" file before i run the program.

//information inside the "StaffList.txt"
James S1325685J12580
Peter S8856325K52650
Ben S1025639Z85250
Ken S9052365B74100
Marry S9352654I75320
John S7754852H99630
Jenny S7042525L74530
May S1256985G15960
Betty S1135565K56360
Kyle S9545530A1234100

[code]....

View 2 Replies View Related

C++ :: How To Delete A Line From Text File Using Fstream

Dec 16, 2014

I'm trying to make a simple phonebook app that can show contacts, add, and delete. I'm pretty new to C++ and fstream functions, deleting a line in my bool erase() function?

#include <iostream>
#include <conio.h>
#include <string>

[Code].....

View 6 Replies View Related

Visual C++ :: Detect ItemID And Delete That Line From File

Oct 14, 2013

I have a text file name fruit.txt that contains the following information of fruit id, fruitName and fruitQuantity.

Code:
1:pear:30
2:apple:20
3:banana:24
4:orange:15
5:watermelon:35

If let's say I key in 2, it will search for the id=2 and delete the whole line and the id of banana which is orignially 3, will become 2 and orange which is orignally 4 will become 3 etc.

I researched on how it can be done and most suggested to put inside a vector and fout the line.

I know how to put the values in the vector but how should I go about searching for the id and if the id is found it will delete that line inside the file.

Code:
ofstream fout;
ifstream readFile("fruit.txt");
while (getline(readFile, line)) {

[Code]....

View 2 Replies View Related

C :: Program Not Read The First Line Of File

Dec 2, 2013

I have been working on a program to scanfile and whenever it encounters what the user wanted it prints it, and it is all right less the first line of the file that the program jumps,

Code:

#include<stdio.h>#include<string.h>
#include<stdlib.h>
void main()
{
unsigned int j=0 ;
char num[100] , str1[100], str2[100];
FILE *fp;

[Code]....

View 3 Replies View Related

C/C++ :: Program Cannot Find Words In The File If They Are On Another Line

Apr 3, 2015

I wrote this code to search words in the file and display if the program found the word or not. when i write the words in the file on the same line (without the endl) like this :

w_toFile << "gilbert";
w_toFile << "lara";
w_toFile << "rana";
i can search any word.

but when i write them with the endl, the program can find only the first word. what can i do to make the program find any word even if they are each on a line?

here is the full code:

#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
using namespace std;
int main (void) {
string wordsearch;

[Code] ....

View 5 Replies View Related

C++ :: Program That Deletes Two Spaces On Each Line In A File

May 17, 2012

I must create a program (a simple main.cpp in console interface) which deletes two spaces for every newline in a file. If a line has no space, it goes straight to the next line to the end of the file. After the program is to resave the file contents into a new file that has the same name as the old, but change the extension to. Modif

The problem is I can not do that ... Do you have a sample code that does this?

View 3 Replies View Related

C/C++ :: Program That Count Empty Line And Display Whole File

Jan 6, 2015

I am new in c programming. I want to write a function that will count the empty line of the file and display the content.

/* ***************************
** creator: firstprint *
******************************/

#include <stdio.h>
/* function that will identify if line is empty or not */
is_empty(char *buffer) {
while(isspace(*buffer)) buffer++;
if(*buffer==0x00) return 1;

[Code] ....

View 4 Replies View Related

C++ :: Program To Search Index File Using Command Line In Linux

Oct 28, 2014

I have code that creates an index file created from a data file of records.

#include <iostream>
#include <fstream>
#include <map>
#include <sstream>
#include <string>
#include <iomanip>
using namespace std;
class Record {

[Code]...

I now need to write a second program that allows the user to enter a command on the Linux command line such as

search 12382 prog5.idx

and returns the information for the record with that key. The code I included for the index file is correct and works properly, but how to write the second program.

Here is the index file created by the first program:

8: blank 0 $ 0.00
12165: Item16 30 $ 7.69
12345: Item06 45 $ 14.20
12382: Item09 62 $ 41.37
12434: Item04 21 $ 17.30
16541: Item12 21 $ 9.99
21212: Itme31 19 $ 8.35
34186: Item25 18 $ 17.75
41742: Item14 55 $ 12.36

The top line is a dummy record, the first number is the size of the file.

View 19 Replies View Related

Visual C++ :: Program To Output A Line For A Specific Age Group - CPP File

Feb 13, 2013

I am suppose to make a program that will output a line for a specific age group,but everytime I execute the exe file it gives me the desired line and also the last line included everytime.Where did I go wrong with it including the last line everytime?

#include <iostream>
using namespace std;
int main() {
double age;
cout<<"Enter your age:";
cin>>age;
if (0<age && age <6)

[Code] ......

View 1 Replies View Related

C :: ANSI Program To Print Out Each Command Line Argument On Separate Line Using For Loop

Mar 5, 2013

I need to write a ANSI program to print out each command line argument on a separate line using a for-loop. also it need to print the name of the executable .so far I have

Code:

#include <stdio.h>
int main(int argc, char **argv) {
int i;
printf("")

[code]....

View 1 Replies View Related

C :: Program Which Writes Out Its Command Line Arguments In Reverse Order One Per Line?

May 7, 2013

l need to write a program which writes out its command line arguments in reverse order one per line. The output from the program should look like this:

% a.out Two roads diverged in a yellow wood
wood
yellow
a
in
diverged
roads
Two

View 9 Replies View Related

C++ :: Program That Reads Text From A File And Outputs Each Line To The Screen - I/O Streams

Jun 15, 2013

I seem to be missing a concept or 2 here ... I am tasked with writing a program that reads text from a file and outputs each line to the screen as well as to another file PRECEDED by a line number ...

In addition, I have to Print the line number at the start of the line and right-adjusted in a field of 3 spaces ...

Follow the line number with a colon then 1 space, then the text of the line.

Another kicker, is I have to grab the data 1 character at a time and write code to ignore leading blanks on each line.

Here is what I have so far:

#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cctype>
using namespace std;
int main() {
char next;
int count = 0;

[Code] ....

View 7 Replies View Related

C :: Reading A File Line By Line (invalid Write Of Size X)

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

C :: Reading A File Line By Line And Storing It Backwards Into A List

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

C :: Copying File Line By Line Using Dynamic Memory Allocation

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

C++ :: Read Line By Line From Text File To String

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

C++ :: Read Txt File Line By Line Write To Vector

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

C/C++ :: Reading From A File Line By Line With No Specified Number Of Values

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

C/C++ :: How To Get Last Line 10 Char In Text File If Last Line Is Null

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

C++ :: String Operation While Reading Line By Line From A File

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

C :: Reading File Line By Line On Windows?

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

C++ :: How To Read Data From A File Line By Line

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







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