C++ :: Searching For Character In String
Jun 19, 2013
I'm trying to find a < character in a document, get it's position. Then find > and get it's position. Then i want to delete all things between that but runtime is terminating my process so i don't know what to do.
The code:
#include <iostream>
#include <conio.h>
#include <stdio.h>
[Code].....
View 6 Replies
ADVERTISEMENT
Jan 30, 2013
I have 80,675 Files, 8,213 SubFolders.
I would like to search each file for a string, which will be last name.
Matches string, outputs path/filename, either to screen or a output file.
I have done this to a single file but never to multiple files and folders.
View 2 Replies
View Related
Nov 3, 2013
New to C++ lambda, got two question in regards of searching for strings within a vector struct.
Minimalistic example:
Code:
struct singleFile {
std::string filename;
};
std::vector<singleFile>myStorage;
myStorage.push_back(singleFile());
[Code] ....
1) why does found always return 0 eventhough the filename exists?
2) I don't know how to pass an actual search string instead of the hardcoded approach as above with filename =="
View 6 Replies
View Related
Apr 12, 2014
I want to make a program that receives the number of lines and collumns of a matrix, a matrix of char, the number of pairs of coordinates and the coordinates. the program has to return the char (or chars) that are on those coordinates on the matrix.
Example:
receives
2 3 ABC DEF 2 1 1 1 2
returns
AB
this is how i tried to solve this problem:
Code:
#include
#define MAX 1000
int main() {
int nlin, ncol;
char mat[MAX][MAX];
int x[MAX], y[MAX];
int ncoords;
int l, c, n;
/* receiving variables and storing matrix.*/
[Code] .....
For some reason that i can't seem to find, this solution is not right.
View 6 Replies
View Related
Apr 2, 2014
Write a function to read and display the contents of names and marks. You then ask the user for a name and using the linear search return the index to the user. If -1 is returned then the name is not in the file. Otherwise write out the name and mark for that student.
Next, sort the arrays, write them out and then ask the user for a name to search for. This time use the binarySearch to return -1 or an index. Display the student's name and mark if found.
void getNames(ifstream& inStream, string names[], int marks[], int numElts);
int linearSearch(const string names[], int numElts,string who);
int binarySearch(const string names[], int numElts,string who);
void selectionSort(string names[], int marks[],int numElts);
void displayData(const string names[], const int marks[], int numElts);
[Code] ....
Now I have worked up some stuff in parts but I am so lost and confused with these specific requirements: Previous questions asked me to sort out a linear search, a binary search and
LINEAR SEARCH:
int searchList(int list[], int numElems, int value) {
int index = 0; // Used as a subscript to search array
int position = -1; // To record position of search value
bool found = false; // Flag to indicate if value was found
[Code] ....
View 3 Replies
View Related
Nov 8, 2012
The program then asks the user for a search string, which may contain white space. The program should search the file for every occurrence of the search string. When the string is found, the line that contains it should be displayed in the following format
nnnnn:Line Contents
That is the line number of the line, 5 columns wide, right justified, followed by a colon, followed by the contents of the line.
And this is what I've got so far:
Code:
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
int main(int argc, char *argv[]) {
ifstream inFile;
string fileName,
[code]....
But this doesn't work. It prints everything in the file, not just the lines where the string is found.
View 9 Replies
View Related
Sep 13, 2014
So I'm trying to create a function that replaces any instance of a character in a string with another. So first I tried the replace() string member function:
In my implementation file
void NewString::ReplaceChar(const char& target,const char& entry)
{
this->replace(this->begin(),this->end(), target, entry);
};
Main program
#include "NewString.h"
using namespace ...;
int main()
[Code].....
Instead of replacing the the l's with y's it outputted a long string of y's. Also, NewString is derived from the string class (it's for the assignment). the header and whole implementation file, already tested.
I've also tried, instead, to use a for loop in ReplaceChar() but I need to overload the == operator and I don't know how I should exactly:
bool NewString::operator ==(const char& target)const {
if(*this == target)
return true;
[Code]....
I want the == operator to test if the value in the char array is equal to target but I'm not sure how to pass in the position. I'm guessing the this pointer in ReplaceChar() is not the same as the one dereferenced in ==() because target is never replaced by entry in the string.
View 5 Replies
View Related
Dec 11, 2014
I have it searching through the entire string letter by letter, looking for spaces, punctuation, etc... yet it still is continuing on with the space.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <stdio.h>
#include <cctype>
#include <algorithm>
[Code] ....
Output:
if(str_word == " ")
//or
if(str_word == ' ')
It does nothing to change it. I am completely baffled.
View 4 Replies
View Related
Aug 20, 2012
I'm trying to get the int value of each character in a string and then add them all together so I can do a 1's complement of the total value. I'm trying to do simple checkum kinda of thing for verification of data.
For example: string DPacket = "Hello World!";
I would like to have each character added and do the ones complement. Will it be easier to convert first to int and then add or any other easier way? So my result should be the decimal value addition of each character and then do the ones complement to that.
View 5 Replies
View Related
Dec 25, 2013
I know how to remove certain characters from a string by using something like this:
Code: string str ("Hello world!");
erase (0, 6);
That's great if I want to do that manually, but say if someone entered a string, how would I automatically remove every other character they entered?
View 4 Replies
View Related
Mar 6, 2015
I want to check whether a certain character is in a string or not but my code is not working
Code:
#include<stdio.h>
#include<string.h>
int main()
{
[Code].....
View 7 Replies
View Related
Feb 26, 2013
Let's say i have a string "file.txt" and i want to insert "_out" to make it look like "file_out.txt"
I don't know how to do this ....
View 8 Replies
View Related
Mar 6, 2015
Copy some characters from char * arg to char * first using a loop with specific conditions.
Code:
char * arg;
// set arg some string...
char first_[25];
char * first;
int length;
length=strlen(arg);
for (n++; arg[n] != '}' || n>=length-1; n++)
strcpy(first,arg[n]); // first += arg[n]; I have strcpy(first,arg[n]); but arg[n] is char and strcpy expects char * ;
how to solve this?
View 2 Replies
View Related
Jun 14, 2013
It's been about two years since I last program c, now I need to do it for a basic project. How would I print out one letter in a string?
For example lets say I have a string called str=[Hello]. I want to display the third letter so just the "l". Here's what I have so far:
Code:
#include<stdio.h>
int main() {
char str[50] = "Hello";
printf("The third letter is : %s
",str[3]);
return 0;
}
View 2 Replies
View Related
Jan 27, 2013
I want to input a string, say: abcdaa so, the program should output:
a
b
c
d
In other words, the program will display each character for only ONCE!!!! And display their frequency. Here is my idea: user will input a string and such string will be copied into another string variable called "checker".There will be a loop and each character will be printed, BUT, first, the program will check if the character to be printed is not equals to all elements of the checker string.
I already have the function to count the frequency of each character
GOAL: to make a program that will accept a string and use the HUFFMAN CODING to compress it.
for(x=0; x<string_in.size(); x++) {
cout<<" "<<string_in[x]<<endl;
for(y=0; y<string_in.size(); y++) {
if(checker[y]==string_in[x])
break;
else
checker[x]=string_in[x];
}
}
View 13 Replies
View Related
Feb 12, 2015
I have an open file dialog that opend the xml file and store the path to the textbox, it returns the path correctly but when i need to store that xml file into the database it tells me that there is an error next to '' because when i try to debug it it gives me "C:\Student Results\FC2015.xml" this results then it breaks. here is my code:
This code returns xml path to textbox
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "XML Files (*.xml)|*.xml";
ofd.FilterIndex = 0;
[Code]....
View 2 Replies
View Related
Mar 1, 2014
I need to make a function that removes a function in a c-string. This is what I have:
#include <iostream>
using namespace std;
char removeCharacter (char *str, char c)
{
[Code].....
View 5 Replies
View Related
Jun 9, 2013
I keep getting this error after I input:
Code:
Unhandled exception at 0x54AE350B (msvcp110d.dll) in Random.exe: 0xC0000005: Access violation writing location 0x0131CA21.
Code:
#include <iostream>
#include <cstring>
//Prototypes
void lastChar(char *);
int main() {
const int LENGTH = 21;
[Code] ....
It builds without any errors. I am just trying to output the last character in the C-string. Am I doing this all wrong?
View 14 Replies
View Related
Nov 25, 2013
I wish to convert a character directly to a string for a top-secret project I'm working on. It needs to be portable across various machines with different sized Indians.
Code:
#include <stdio.h>
int main(void)
{
const int i = 0x0041;
const char *str_p = (char *) &i;
}
[code]....
I want this to output an 'A', but I'm not sure this code will work on my friend's mom's S/360.
View 2 Replies
View Related
Nov 19, 2013
I am still working on my project which will be reading some old data from some old DOS files. The data stored there is naturally, char*. Once I read in my character array, how do I assign this to a wstring since my application is UNICODE?
Here is my current solution:
wchar_t* Class::Function(char *pName) {
//I verify the pointer and such first, then do the below
this->_Name.assign(pName, (pName + strlen(pName));
return this->_Name.c_str();
}
Am I on the right track here?
View 9 Replies
View Related
Oct 2, 2013
I have been trying to write a function which can convert a number from an unsigned long integer to a readable ASCII character string. this is what I have come up with, but I am receiving some very strange characters in return. Could the problem be that I am telling a char to = an unsigned long int, (cString[i] = product[i])?
void convertToString(unsigned long con) {
unsigned long product[10];
char cString[10];
const unsigned long begConvert = 10 ^ 10;
[Code] ....
View 4 Replies
View Related
Oct 24, 2013
I am trying to take a string that is within the main function, and write a void function that gives me the most common alpha character used inside the string. How to mix a string and an array together like that as I am not too familiar with arrays yet.
View 8 Replies
View Related
Apr 19, 2014
In the following char array, notice the use of a backspace character in a string literal: ''.
char text1[50] = "aHello,
World! Mistakee was "Extra 'e'"!
";
What exactly does a backspace character do here? When the compiler evaluates this line, does it actually delete the previous character, like when you press the backspace button on the keyboard?
View 1 Replies
View Related
Jan 11, 2013
I need to find position of certain character in string, so i made a function but it doesn't do what i thought it would.
Consider this string:
std::string line = "<foo> <foo> <foo> <foo> <foo>"
I need to find position of a third '>' character so i can get:
std::string other = "<foo> <foo> <foo>";
This is my function that fails:
std::size_t find_third(const std::string& line) {
std::size_t pos = 0u;
for(std::size_t i = 0; i < 3u; ++i) {
std::string tmp = line.substr(pos);
pos = tmp.find_first_of('>');
} return pos;
}
View 6 Replies
View Related
Jan 12, 2013
I am trying to record some information in a file and allow user to delete a record. I am facing this message in Autos section of MVS (Error reading character of string). Here is the code:
int removeRecord(string name, int &row)//remove a record
{
const string data="database.txt";
fstream records;
records.open(data.c_str());
const string cpData="temp.txt";
[code].....
If I delete the any row (except last roe) it works but then add a copy of last record (sometimes fully sometimes partially) at the end of the file!! if i delete the last record it does not do anything.
View 1 Replies
View Related
Nov 30, 2013
I would like to insert some character after each number of my string .. I found how to insert before each character, but what I want is :
string str = "12 + 5"
insert ^ after each number
Output = "12^ + 5^"
View 7 Replies
View Related