C++ :: How To Search For A Substring In A File

Jan 12, 2013

How I can search a sub string in a file? Length of sub string is Variable and the number of search is indefinite.

View 15 Replies


ADVERTISEMENT

C++ :: Search Specified File For All Instances Of Substring

Mar 24, 2012

I'm trying to search a specified file for all instances of substring "abbaa."

The professor is making us use a 6x3 array in order to understand finite state machines.

Well the code I wrote runs perfectly, but the case for '/n' doesn't catch. It just flows through without it.

Significant portion of code:

Code:
if(fin) {
fin >> inChar;
while(fin) {
switch(inChar) {
case 'a':
currentState = state[currentState][a];

[Code] .....

View 3 Replies View Related

C++ :: Substring / Loops And Writing To A File

May 21, 2013

Here are the requirements for a project I am working on.

Write a function that will write only unique ip addresses to a file (just the ip address, not the entire line).

Write a function that will search for an ip address and display all page requests for that ip address.

The ip is pulled from a "weblog.txt" file which has been put into a vector and sorted. I am having trouble with the loop to pull only unique ip addresses from the vector.

Code:
#include<iostream>
#include<vector>
#include<fstream>
#include<string>
#include<algorithm>
void nonmember();
void sortnonmember(std::vector<std::string>& webvector);

[Code] .....

View 1 Replies View Related

C Sharp :: Substring From Number In Text File

Oct 15, 2013

How to substring first 8 digits from number?

I have text file with around 10k lines. Each line contains number with length 12-14 digits. I want to take only first 8 digits from each number and writ it in new file.

View 1 Replies View Related

C++ :: How To Do Substring To Get Last 4 Characters

May 8, 2013

let says i have char *yytext = "p103_stb" 0r "p0_stb" or "p100_stb"

How to do substr to get the "_stb" in C?

View 12 Replies View Related

C++ :: How To Remove A Substring

Aug 4, 2014

I have a C-based string. trying to remove some sub-string, I got at:

char str[]="alireza tavakkoli";
char* pos = strstr( str, "reza");
for(int j=pos-&str[0];j<pos-&str[0]+strlen("reza");++j)
str[j] = 7;

But I don't like the last line.isn't there a better solution?

View 7 Replies View Related

C++ :: Find Substring From A String

Apr 23, 2012

I am stuck in some logic and want to write a program to do following tasks : I have three string variables to be compared to each other,a string having sub string & hierarchy string!!

1.) name1=john name2=tom_john_tom name3=alextom_john
thus we need to search john from name2 and name3 and if name1 exists in both name2 and name3 then ok else check for step2

2.) name1=a.b.c.d ,name2=a.b.c.d and name3=a.b.c.d
we need to compare each string seperated by a dot in all three variables and we need to match each string seperated by a delimeter "."
if name1.a==name2.a==name3.a and name1.b==name2.b==name3.b ,name1.c==name2.c==name3.c and name1.d==name2.d==name3.d then its a match
else its a mismatch

Also,the catch is we can have name1 ,name2 and name3 in format name1=*.*.*.* and name2=*.*.*.* and name3=*.*.*.*
where * defines it can be any value to be matched

name1=government.india.public.property
name2=rural.roads.maximum.x
name3=government.india.public.sales
name4=rural.roads.minumum.x

If operator wants to match only the second field , then the logic should be like:

If the Value is to be matched = (*.#.*.*)
then "matched"
Else
its a mismacth

# => for this field of name2 and name3 shall be same
* => for this field name2 and name3 shall be ignored for comparison

to obtain option1 we can have find function and substr however pls suggest how to approach for second option !!!!

View 1 Replies View Related

C :: Parsing A Line To Extract A Particular Substring?

Mar 14, 2014

Suppose I have read a line from an ASCII file with fgets(). Now I want to parse the line, which looks something like this: Code: # John Q. Public et al. 2014, to be submitted The name, "John Q. Public" is what I want. However, the name can be anything, consisting of 1 or more tokens separated by spaces. it could be "John" Or "John Public", or "Thurston Howell the 3rd", or etc... Bascially, I need to get the entire substring between the first hash mark, and the "et al" in the line. I tried this: Code: sscanf(line,"# %s et al.",name); But I can only get the first token (which, in this case, is "John").

View 2 Replies View Related

C/C++ :: Finding And Printing A Substring In A String?

Feb 21, 2015

i couldnt solve the algorithm exactly. The program asks the user for a string. "Bugun h@v@ cok g'uzel" for example. then the program asks for another string. If that string doesnt exists in the main string program should say there isnt any substring. If it exist then the program should print the remaining part of main string. For example:

Write the first string: Tod@y weather is be'@utiful
write the substring : ug
>>ugun h@v@ cok guzel
write the substring :wldnqwbdbj
>>there isnt any substring
Here where i came so far

#include <stdio.h>
int main()
{
char mainstr[50],substr[50];

[Code]....

View 7 Replies View Related

C/C++ :: How To Compare A String To A Vector Substring

May 9, 2014

I would like to compare two strings, one of which is an independently stored string - the other being a string within a vector. However, i do not know how to do this, as

string thisString = "yes";
vector<string> stringHere;
stringHere.push_back("no");
if (thisString == stringHere[0]) {
cout << "It worked." << endll;
}

does not appear to work.

View 2 Replies View Related

C++ :: Given A String How To Find Longest Substring With All Unique Characters

Feb 9, 2015

I am new to C++ programming, writing a program for the below question:

given a string, how to find the longest substring with all unique characters.

View 1 Replies View Related

C++ :: Search And Find The Shortest Queue And Search After Some Condition?

Mar 7, 2013

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

[code].....

View 1 Replies View Related

C :: Search File For String

Aug 22, 2014

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.

Code:

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
}

[code]...

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.

View 5 Replies View Related

C++ :: File Info Search?

Feb 27, 2013

I am looking for a way that I could check the information of a folder and a drive, to show the data size and storage amount (KB, MB, GB). This is so that I can compare the size of a folder to the storage capacity of a disk drive.

View 2 Replies View Related

C++ :: Function To Search For A File In Computer

Apr 4, 2013

#include <iostream>
#include <cwchar>
#include <string>
#include <Windows.h>
using namespace std;
#include <shellapi.h>
#pragma comment(lib,"shell32.lib")
static HWND hBut;
#define ShellExecute;

[Code] ....

My function is the issue. I'm not sure how to write a correct function to search your computer for file 'a'.

View 3 Replies View Related

C/C++ :: File Search Not Starting At First Record

Aug 10, 2014

Below is a snippet of my code in which it loops through a file trying to find the matching record of a selection given by the user. I use tellg() to tell me where the search begins and it does in fact start at the beginning. But when the search actually executes, it starts at the last record, loops once, and ends, as it does not find the matching record (when the user enters '24' for example)

void Hardware::updateExistingRecord(ofstream &addRecordInfo, ifstream &updateRecord, Hardware &_records) {
//selection on which field to update
enum Field { RECORD_NUMBER = 1, TOOL_NAME, QUANTITY, COST, EXIT };
cout << "Enter record number you would like to update
";
cout << "Enter zero to exit
?";

[Code] ....

View 10 Replies View Related

C++ :: Binary Search And Sequential Search Algorithm

Sep 16, 2013

Write a program to find the number of comparisons using the binary search and sequential search algorithms

//main.cpp
#include <cstdlib>
#include <iostream>
#include "orderedArrayListType.h"
using namespace std;
int main() {
cout << "." << endl;

[code]....

View 4 Replies View Related

C++ :: Binary Search Or Linear Search For 3D Array

Oct 7, 2014

inputting a search array. I tried putting a binary search but I can't get it to work. everything else works up until I put the value I am searching for in the array, then it just crashes.

How it suppose to work: input 2 coordinates with a value each then it calculates the distance between them then it suppose to let user search the coordinates for a value and state if found which coordinate it is at.

#include "stdafx.h"
#include <iostream>
#include <iomanip> //for setprecision
#include <math.h>

[Code].....

View 3 Replies View Related

C++ :: Lexing File Into Binary Search Tree

May 22, 2013

Standard example. I have a large text file and I wish to lex it into words. I tell the program that all words are delimited by ' ' ';' ':' and ''.

When I run the program it seems to be outputting the occurances of the letters and not the words. Im gobsmacked, I dont know what the hell is going on. Heres the function that lexes letters and not words. I want words dammit words!!

First youll see I define root node and point it to null; This forms the base of the BST. Then keep munching one character at a time until EOF reached. If the character is not a delimiter, assign it to "word" string, character by character. If it is a delimiter, take the so-far-constructed "word" and chuck it in the BST, then clear the word string through .clear().

Repeat until done. But its not working.

Code:

struct masternode* lexical_scanner(ifstream* inputfile) {
string word;
char c;
struct masternode* root = NULL;
while (c!=EOF){

[Code] .....

All the other functions in the source file are just fine, I've tested them in other apps and they are purpose built.

View 6 Replies View Related

C/C++ :: Search In File And Extract Content Between 2 Strings

Jun 8, 2014

I need to develop a simple program, i have 2 variables (begin, end), and i need to search in a file, And extract the string between the Begin and the End variables to a new File, For Example:

my text file: file.txt:

some text here<StartHere>more text here</EndHere>text text

C++ Program:

//Declear 2 variables
strcpy_s(begin, string("<StartHere>").c_str());
strcpy_s(end, string("</EndHere>").c_str());

//And now, search in the Text file, And Extract the text between the begin string and the End string.
<...>

The Result should be: NewFile.txt with the content:

<StartHere>more text here</EndHere>

That's it!, Here is what i have for now:

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main() {
int ocurrences_count = 0;
int ocurrences2_count = 0;
char word[20]; //this array will save user input

[Code] ....

View 1 Replies View Related

C :: Search Table And Replace Values In Text File

Feb 3, 2015

I have to develop a C program that reads a very complex txt file (output of a calculation code, so full of mixed text and numerical tables), search for a specific table in it and individuate/print or replace a specific value with assigned position in the table.

View 2 Replies View Related

C++ :: Use Find Function To Search For A Line In Text File

Oct 28, 2013

I'm trying to make a program that will search for a line in a text file using a non default delimitor at the start of the line. An example line in the text file would be as follows:

F Mary Smyth, 19, United Kingdom

I have been able to use the find function to search for and return the 'F' character but would like it to then display the whole corresponding line. Is this possible with the find function?

ifstream readFromFile("data.txt");
string Destinations[1] = {"F "};
string data;
while(!readFromFile.eof()){
getline(readFromFile,data);

[code]...

View 2 Replies View Related

C :: Create Word Search By Reading In Characters From A File Into Array

Sep 30, 2013

So the plan is to create a word search by reading in characters from a file into an array. This is my code so far, nowhere near finished but have encountered a problem already:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ROWS 20
#define COLUMNS 20
int main()
{

[Code]...

My question is to do with the section highlighted in red... I can't really see why it is not printing out my array (wordsearch), it's probably very basic but I have no C experience so am not too confident in what I'm doing.

View 1 Replies View Related

C :: Search A File For Specif Data And Update It (random Access)

Nov 9, 2014

The file name is "movie.dat" and currently i was able to save data into the file in this order:

[movie_code] [movie_dur] [movie_title] [movie_rating] [movie_dir] [movie_genre] [movie_status]

[12345] [120] [Movie] [PG13] [Director] [Comedy] [Active]

I want to search for the "movie_code" and change the [movie_status] from Active to Inactive.

So lets say for example i have a movie code 12345 saved in my movie file. I want to change the value from "Active" to "Inactive"for argument sake.

This is the code i was trying to do it with:

Code:
FILE *movie_fp;
movie_fp = fopen("movie.dat", "r+b");
int m_code;
MOVIE movie_data;
printf("*** Welcome to the movie updater! ***

[Code].....

View 3 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

C++ :: How To Search Form Insensitive To Case Sensitive - File Handling

May 23, 2014

How to search form insensitive to case sensitive? I'm trying to emulate the behavior of the function "grep" in Unix.

#include <iostream>
#include <fstream>
#include<string>
#include<vector>
#include <ctype.h>
using namespace std;
int main(int argc, char** argv) {

[Code] .....

View 3 Replies View Related







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