473,387 Members | 1,882 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,387 software developers and data experts.

Converting a char array to a string array

Hi

I have written a function that will search through a document and extract some data. The function takes one letter at a time and then stores it in a char array 'array1'.Now I need to convert it into a string array but I am having great trouble getting the code right.

I am trying to use the 'assign' function but it does not seem to be working.

I hope that you can help me!

Expand|Select|Wrap|Line Numbers
  1. void SearchforVars(string Line,int initial, int &start_position, int &end_position, int one, int two)
  2. {
  3.     char array1[100];
  4.     string varname;
  5.  
  6.     for (int i= initial;i < Line.length(); i++)
  7.     {
  8.  
  9.         if ((Line[i] != one) && (Line[i] != two))
  10.         {
  11.             start_position = i;
  12.             break;
  13.         }
  14.     }
  15.  
  16.     int x = 0; 
  17.  
  18.     for (int n=start_position;n < Line.length(); n++)
  19.     {
  20.         if (Line[n] == one) 
  21.         {
  22.             end_position = n;
  23.             break;
  24.         }
  25.  
  26.         dataout << Line[n];
  27.         array1[x] = Line[n];
  28.         //cout << array1[x];
  29.  
  30.     }
  31.     varname.assign(array1);
  32.     cout << varname;
  33.  
  34. }
  35.  
Thanks!
Dec 1 '06 #1
2 2084
DeMan
1,806 1GB
A string is a char array, which is why your function stores it in one. A string array refers to an array full of strings (which I suspect is not what you mean), A String is merely an array of characters , so an array of characters is a string (but not a string array) [and a string array is an array of strings]

Perhaps if you elaborated to show the problem(s) you have with the current code (?)
Dec 1 '06 #2
Hi

Thanks for your help, sorry if i didn't explain my problem very well. I am in fact trying to produce an array that holds thousands of strings. At present my code parses a document and retrieves 11 different types of data and stores them in a text file. I then want to uses this data in a different application. But before I do this I want to store the different data in 11 different arrays.

So far my code reads in the data and puts it into an array. I then want to put the data from that array into specific arrays for each data type once it has been extracted.

Can you think of the best way to do this?

Thanks
Dec 1 '06 #3

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

Similar topics

5
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do...
4
by: jagmeena | last post by:
Hello, I am sure this problem has been addressed before, however, I could'nt get a suitable solution to my problem. Hence I am posting here. Thanks a lot for all your help. The code I have is ...
4
by: x | last post by:
converting 1944 to '1','9','4','4' how can I convert a number such as 1944 to a character array? thanks!
6
by: karthik.naig | last post by:
Hi, This was the routine I wrote earlier to convert a C++ string to a char array. But I found that the char* array consisted only of junk after returning from the below function.
4
by: Prabhu | last post by:
Hi, We are having problem in converting a byte array to string, The byte array has char(174), char(175), char(240), char(242) and char(247) as delimiters for the message. when we use...
18
by: Marcio Kleemann | last post by:
I need to force the first letter of each word in a line of text to uppercase. The text comes from a TextBox control in a Web Form. I'm new to ..NET and am having a problem. Since I can't modify...
2
by: claire | last post by:
I have a char that i convert to a string as follows m_tHeader.m_sshortname is defined as char; string result = new string(m_tHeader.m_sshortname); The problem is that any '\0' chars in the...
3
by: fakeprogress | last post by:
How would I go about converting this C code to C++? /* LIBRARY is an array of structures */ /* This function compares 'tcode' with */ /* existing codes in the array. */ /* It...
0
by: anide | last post by:
Hi all I’ve some problem, I’m trying to converting a sorting algorithm from C++ to C#. In C++ I’ve compiled it using MSVC and its working properly, and in C# I’m using .NET Framework 2.0 (Visual...
1
by: vcbytes | last post by:
I am having a problem with the following code: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { String^ texts = textBox1->Text; char *text =...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.