Solved

Beginner: merging array with string ???

Posted on 2000-04-19
9
221 Views
Last Modified: 2010-04-02
hi my code is following:

void CW1Dlg::OnUpdateEdit1()
{
      UpdateData(TRUE);
      phoneNumbers[1] = m_strMessage+phoneNumbers[1] ;
      MessageBox(phoneNumbers[1]);
}
but theres only an accumulation of the umbers not a merging.
i want array number 1 merged with m_strMessage.
Can anyone help ?
Thanks
0
Comment
Question by:peter_b
  • 5
  • 4
9 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 2730996
We don't know what these things are, so it is hard to answer.  

However, if you are using C-style strings. you cannot concatenate them using +, you must use the strcat() function like

char String1[100] = "this is";
char String2[] = "A test."
strcat(String1,Strng2);

Makes string1 store "this is a test";

However, using C-style strings in C++ is not hardily recomended.  It depends on many factors, but usually you are better of using s string class, like the STL stirng class.
0
 

Author Comment

by:peter_b
ID: 2731110
its Visual C++ 6 i am fighting with.
So how can I merge then ?

0
 
LVL 22

Expert Comment

by:nietod
ID: 2731782
Well I stil; don't know what "they" are.   I guessed that you are dealing with character strings, but that might not even be true.  If they are strigns, how did you declare them?  if they aren't what are they.   You have to understand that I have only 3 lines of code to work with.  These lines use 2 undefined variables, an undefined class, and an undefined function.  I am an expert, but not a psychic...
0
 

Author Comment

by:peter_b
ID: 2733336
sorry i am a beginner working with some books i follow.
i declared m_strMessage with the classwizard to be a string value. It comes from user input (text box 3 numbers alowed only).
the declaration of the array is:
int phoneNamesCount = 1;
CString phoneNames[]      = {"Ve", "B", "Ba"};
CString phoneNumbers[]      = {"0622370", "", ""};

so i need to add the user input before the number 0622370 the second third...
i simply dont know the command to merge them. I allways get lost  in MSDN library...

thanks for helping.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:peter_b
ID: 2733564
DDX_Text(pDX, IDC_EDIT1, m_strMessage);
....
m_strMessage = _T("");

thats all i can find on declaration of the strings
0
 
LVL 22

Expert Comment

by:nietod
ID: 2734072
DDX_TEXT is used for dynamic data exchange (DDE).  A you using DDE?

As far as I know, this does not work with strings.  This is out of my area of expertise, but it seems that the last parameter, m_strMessage int this case, is numerical in nature.  i.e. it must be a number, not text, not a string

Wait, it can be a CString though.  Did you declare m_strMessage as a CString?  A CString is a string object, that is, a c++ object that acts like a character string.

Note I am leaving town today in about 6 hours.  i will be back in 4 days.

>> so i need to add the user input before
>> the number 0622370 the second third...
What do yuou meant by "add"  do you mean actually--numerically add the values.  That cannot be done directly.  You have to convert the value _represented_ by the strings to a numeritcal data type of some sort.  Then add this numerical value.  Then convert this value back to a string representation.

Or do you mean combine (concatenate) the strings?  You can combine two strings with operator +.  Like
CString X = "this is ";
CString Y = "a test";
CString Z = X + Y; // Stores "this is a test.";
0
 

Author Comment

by:peter_b
ID: 2734317
still
UpdateData(TRUE);
phoneNumbers[1] = m_strMessage+phoneNumbers[1] ;
MessageBox(phoneNumbers[1]);

concatenate dont know really what i need is:
333+444 = 333444

if i enter 1 messagebox shows 1
i enter another 2 messagebox shows 121
another 3 --> 123121

so this is absolutely not what i need...
i thought with CString phoneNumbers[] = {"0622370", "", ""};
phoneNumbers[1] would be 0622370
now it is overwritten with what i enter in the box.


using DDE : i dont know :)
0
 
LVL 22

Expert Comment

by:nietod
ID: 2734436
If you enter "1", where does the 1 get stored?

If you don't know what it is, you're not using DDE.  Except you are using it....  Did this code come from somewhere?
0
 

Author Comment

by:peter_b
ID: 2734439
UpdateData(TRUE);
CString Number = "06223";
phoneNumbers[1] = m_strMessage+Number ;

ok works like this
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now