473,385 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

what can i use to find a series of characters in a 2d vector of character?

4
I am just starting in c++ programming in Linux and currently, I have a 2d vector of characters, what function (or functions )can i use to find a series of characters in my vector? For example, I want to find 'h' 'e' 'l' 'p' within the 2d vector.
Feb 15 '07 #1
5 1509
Ganon11
3,652 Expert 2GB
Is it a vector, or a 2D array?

I assume your array will be containing phrases, something like

Expand|Select|Wrap|Line Numbers
  1. [h][e][l][l][o][ ][w][o][r][l][d][\0]
  2. [m][y][ ][n][a][m][e][ ][i][s][\0][ ]
  3. [c][a][n][ ][y][o][u][\0][ ][ ][ ][ ]
  4. [h][e][l][p][ ][m][e][?][\0][ ][ ][ ] // contains help at array[3][0]
Feb 15 '07 #2
AdrianH
1,251 Expert 1GB
I am just starting in c++ programming in Linux and currently, I have a 2d vector of characters, what function (or functions )can i use to find a series of characters in my vector? For example, I want to find 'h' 'e' 'l' 'p' within the 2d vector.
You are going to have to be a bit more clear. Perhaps if you can give us what was given to you it would give us an idea what you are asking. Mind you we will not do your work for you, we will try and point you in the right direction, give you resources which will help and help debug your code for you.

Hope we can help.


Adrian
Feb 15 '07 #3
tinie
4
You are going to have to be a bit more clear. Perhaps if you can give us what was given to you it would give us an idea what you are asking. Mind you we will not do your work for you, we will try and point you in the right direction, give you resources which will help and help debug your code for you.

Hope we can help.


Adrian
What I have is a two 2d vector, which like a 2d array and it looks like what Ganon11 illustrated in the previous post. Let's take what was illustrated in the previous reply. Is there a predefined function in c++ (or in the STL) that could help me find 'h' 'e' 'l' 'p' in the 2d vector? the 2d vector is constructed as:

Expand|Select|Wrap|Line Numbers
  1. vector <vector <char> > notes;
and the elements are placed in the vector by making calls to push_back()

i hope i was able to make it clear....
Feb 15 '07 #4
AdrianH
1,251 Expert 1GB
What I have is a two 2d vector, which like a 2d array and it looks like what Ganon11 illustrated in the previous post. Let's take what was illustrated in the previous reply. Is there a predefined function in c++ (or in the STL) that could help me find 'h' 'e' 'l' 'p' in the 2d vector? the 2d vector is constructed as:

Expand|Select|Wrap|Line Numbers
  1. vector <vector <char> > notes;
and the elements are placed in the vector by making calls to push_back()

i hope i was able to make it clear....
Much clearer. Well, there are many ways. But the easiest one is to treat the vector as an array. So to access the 3 character in the 2 vector, you would do this:
Expand|Select|Wrap|Line Numbers
  1. notes[2][3]
.

Does this make sense?


Adrian
Feb 15 '07 #5
Ganon11
3,652 Expert 2GB
You can use a set of nested for loop, like so (where size1 is the vector[x] size, and size2 is the vector[][x] size):

1) Looping from 0 to size1 (index i),
2) Looping from 0 to size2 (index j),
3) If the current char (vector[i][j]) is 'h',
4) Check if the next chars (vector[i][j + 1], vector[i][j + 2], etc. are 'e', 'l', 'p', etc. and NOT out of bounds
4)a. If they are, you have found the string
4)b. If not, keep searching
Feb 15 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: lkrubner | last post by:
I'm worried about idiot users that write long essays in Microsoft Word, then log into their accounts and bring up an HTML form and copy and paste the essay and hit submit. Or perhaps they do this...
2
by: Steven T. Hatton | last post by:
I'm still not completely sure what's going on with C++ I/O regarding the extractors and inserters. The following document seems a bit inconsistent:...
15
by: Jeannie | last post by:
Hello group! I'm in Europe, traveling with my laptop, and I don't any compilers other than Borland C++ 5.5. available. I also don't have any manuals or help files available. Sadly, more...
9
by: mistral | last post by:
What is difference between two encoding methods below and what method can be considered more "web safe", fully retaining functionality of the original source code, without the danger of...
4
by: mistral | last post by:
Can anyone help to identify what this encryption used in this script? <html> <body> <script type="text/javascript" language="JavaScript"> function decrypt_p(x){ var l=x.length, b=1024,...
123
by: plenty900 | last post by:
I was looking over someone's C++ code today and despite having written perfectly readable C++ code myself, the stuff I was looking at was worse than legalese. The people who are guiding the...
38
by: Bill Cunningham | last post by:
When I want to clear memory space this is what I typically do myself, char a; int i; for (i=0;i != 100;++i) a='\0'; Now with the function memset I could do the same thing and it would be...
1
MrPickle
by: MrPickle | last post by:
I am tokenizing a string and sending it to a ofstream but I am getting strange results. The \n sequence isn't working; it doesn't go to a new line. I'm getting Chinese/Japanese characters in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.