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
ADVERTISEMENT
Nov 2, 2013
It appears that when you enter command line arguments or use fgets() to input a string you can assign that string to another string variable using the assignment operator. But when you read from a file, you can't do that, you get a segfault. It seems the only way to get around that is to malloc the string and use the strcpy function.
Code:
#include <stdio.h>
struct person {
char *names[2];
};
void readFile(struct person p){
FILE *file = fopen("names", "r");
[Code]....
View 3 Replies
View Related
Jul 19, 2013
I have read that the Erase-remove idiom is the way to go. I have a rough understanding of how this works but am unsure whether I can implement a match-counter along with it.
For counting alone, I would use something like this:
Code:
std::vector<std::string> v; // contains duplicate strings in different elements
std::string term = "foo"; // search term, changing at runtime as well
unsigned int matches = 0;
for( auto e : v ) {
if( e == term ) {
[Code] .....
I'm not sure how (or if) I can combine the two things. That is, I don't know how to integrate a function comparing two (changing) strings into the remove_if() method. Nor do I know how to increment a counter during iteration.
The vector is extremely large, so speed is paramount. I think there are many other avenues for optimization, but decreasing the vector's size for each consecutive search could deliver a big speed boost for subsequent searches I imagine, as traversing it holds the biggest cost.
View 3 Replies
View Related
Apr 27, 2013
I have a text file with scores and names.
I have to read the score into an array and the names into an arrays also
27,Tom Jefferson
23,Ozzie Osborne
18,Wilt Chamberlain
15,Marie Antoinette
I've gotten the score to display correctly, but i cant get the full names. My function only reads the first names
View 8 Replies
View Related
Aug 2, 2013
I need to write a program that reads a paragraph from a file (i dont know its length) and i need to read it with spaces
i thought of using getline() function but there were problems:
1) how to detect End Of File
2) how to use getline while reading from file
and thought of reading one character at a time but it didnt read spaces
View 4 Replies
View Related
Nov 28, 2014
I wanted to improve the game from my last thread. I want to read and store a question in this format: Code: Who invented the BALLPOINT PEN?
A - Biro Brothers
B - Waterman Brothers
C - Bicc Brothers
D - Write Bothers
But when I use fgets() to read the string, it reads all the ' ' literally instead of outputting a real newline. Like if it read the above question, I want it to print something like this:
Code:
Who invented the BALLPOINT PEN?
A - Biro Brothers
B - Waterman Brothers
C - Bicc Brothers
D - Write Bothers
View 3 Replies
View Related
Feb 25, 2014
I am trying to read strings to an char array from an .exe file and then i would check some of the strings, but the problem is that the only thing that is read from the file is the first string (MZ) and an 'square' that is some incorrect character. I am using fread to read from the file. Here is my code:
FILE * pFile;
long lSize;
char * buffer;
size_t result;
pFile = fopen("my_file.exe", "rb");
if( pFile == NULL) exit(1);
fseek(pFile,0, SEEK_END);
[Code] ....
(I want to read the whole file, its not that big)...
View 14 Replies
View Related
Feb 26, 2015
I need a program that reads the number of lines of a file and then several (max of 20) lines of text from a .txt file so an example of the .txt file is: 2 This is the first string This is string number 2 So it first reads the 2 and then reads the two lines of text. It stores the text in an array of pointers. The code i have so far is:
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
[Code].....
It doesnt give me any errors but all it does is keep running and doesnt print anything out kind of like its in an infinite loop although i dont see how that could be possible.
View 1 Replies
View Related
Oct 17, 2014
I have to make a program to read a file with strings and determine if they are palindromes. The problem is that the program says that they're all palindromes.
int main() {
ifstream inFile;
ofstream outFile;
inFile.open("in.data");
outFile.open("out.data");
if (!inFile || !outFile) //to display error if input files are invalid
[code]....
View 3 Replies
View Related
Jun 11, 2014
Here's what I want to do:
So, basically the user imports a list of strings from a CSV file and the lines get read line by line and sorted in a listbox. If the user uploads the same file again that contains the same list of strings, a confirmation box with the following is supposed to be displayed:
"The list is the same. Are you sure you want to import this list of strings?" The options are yes, no, maybe.
If the user clicks on yes, all the strings get saved/put into the listbox regardless of whether or not they are repeated. No allows the user to to cancel the whole operation and return back to the screen for all samples. Maybe allows the user to individually pick which one they want saved or not. Maybe takes the user to a yes or no confirmation dialog box and it loops through all the strings in the csv file until the user has picked yes (accept) or no (deny). Only the confirmation box with yes and no should be looping.
What I have so far:
-Two confirmation boxes (I decided it would be easier for me to create two views and two viewmodels just for confirmation box setup - one with confirmation box of yes/no/maybe and one with confirmation box of yes/no).
-All the event handling is set and done.
-Reading the CSV file and checking for duplicates.
What I have problems with:
-When the call the confirmation dialogs...
Here's a snippet of what I have:
public void ReadImportedSamples(string filePath)
{
string line;
try
{
using (DDataContext context = new DDataContext())
{
using (StreamReader sr = new StreamReader(filePath))
{
[Code]...
So, I have two confirmation boxes, confirmationWindowSamplesListYN (only yes and no) and confirmWindowForSamplesList (with maybe).
Everything is set up fine. I am just wondering when the call the proper confirmation dialogs so that I can get the behavior above?
View 14 Replies
View Related
Feb 24, 2015
The requirement was to set the txt files information equal to a variable before and not to put it directly into the array.
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
const int MAX = 24;
struct applicant_info {
[Code] .....
the txt doc looks something like this: file name: jobs4.txt
View 2 Replies
View Related
Feb 23, 2015
I have been skimming and searching but dont know how to word the search just right to find what I need to know. I have written simple stuff with the support of tutorials like weight conversion or loops counting up to a set number. Nothing amazing. The other day I found out how to input and print a string rather than a single text character which i though was bad ass. I even got it to read multiple strings on a single line and found a way to read multiple lines. I can even format it to read both integers and characters on the same line as long as I know the predefined format.
On to my question... How do I read multiple lines with both carecters and integers. for instance:
nissan 1996
toyota 1998
or more comples like
nissan gtr 1996
toyota markii 1998
I want to use
int year;
char make[10]; maybe need to use char make[10][10]; for an array i would guess.
char model[10]; optional for the extra data
but reproduce what i read in a different order. say...
1996 nissan
1998 toyota
vice the original format.
this is what I have tried.
Code: scanf("%s %s", &make,&year);
//The way I seen to read multiple lines was on here
scanf("%[^/t]", %make);
But this wont let me separate the two into two differnet definded data types. Let alone use printf to display them in reverse order.
View 1 Replies
View Related
Sep 10, 2014
How to do self deleting of exe file when it is run'd.
View 2 Replies
View Related
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
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
View Related
Oct 10, 2014
I want to read a string of unknown length from stdin. I tried to follow the approach from this link.
[URL]....
My code is like this:
Code:
#include <iostream>
#include <string>
using namespace std;
int n;
cin >> n;
cout << "The value of n is " << n << endl;
string str;
getline(cin, str);
cout << "The entereed string is " << str << endl;
What I have noticed is that if I take integer input from cin (cin >> n in the above code before getline, the control does not stop on getline to take str as input from the console. If I don't do (cin >> n) before getline then the control stops on getline and takes the string as input.
What is the best way to read from console multiple strings of unknown length in combination with the integers?
View 1 Replies
View Related
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
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
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
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
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
Nov 24, 2013
I have this code for a computer project... (store management) but the character strings are not copied on text file..
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class Store {
public:
char *item_name[5];
store()
[Code] .....
Now when i run the program, it gives a error :::
ERROR
address 0x0
How can i write these strings to the text file?
View 2 Replies
View Related
Apr 19, 2013
I want to input data into text file while not deleting the original data in the file and I use something as
ofstream writefile;
writefile.open("example1.txt");
if (writefile.is_open()) {
for(j=0; j<N; j++) {
[Code] ....
But this will delete the original data.
View 3 Replies
View Related
Apr 17, 2014
I'm working on a project, and I'm trying to fill in various vectors from a given input file. The input file looks like:
<catalog>
<book id ="bk101">
<author>O'Brien, Tim</author> ....etc
My load vectors function looks like this: void load_vectors(vector<string>&id, vector<string>& author...etc)
I can't assume a limit on the number of books etc listed in this catalog, so I'm using the eof() function. However, I don't know how to write the loop to gather the correct strings and place them in the vectors.
Code: while(in.eof())
{ string text;
int index, index2;
getline(in, text);
int index = text.find("<author>");
int index2 = text.find("</author>");
a = index.lenght();
author.pushback[i] = text.substr(index + a, index2);
}
View 3 Replies
View Related
Aug 10, 2014
I have been trying to write this program that reads a file of courses and then stores only the unique courses in an array of strings.
for some reason it crashes while reading the 2nd line.
printf within the function are just for me trying to trace the problem.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char** uniqueCourses(FILE *fp, int *wordCount);
int main()
[code].....
View 5 Replies
View Related
Mar 5, 2013
My objectives for this program is to open and read a file "dict.txt" which has the following data:
4
dog
pepper
marker
teapot
It needs to rotate the inner letters one to the right so you'd end up with "mrkear" etc, and then write those words into a new file "scramble.txt" one per line.I'm having a lot of problems understanding the program. Compiling is giving me a lot of warnings/errors.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXW 10 //max number of words in file
#define MAXS 81 //max size of string
}
[code]....
View 2 Replies
View Related