Hi,
i have a problem,
i am writing the initials and the surname on one line of code, how do i copy just the initials and leave the surname, and put the initials on another line?
Thanks
Hi,
i have a problem,
i am writing the initials and the surname on one line of code, how do i copy just the initials and leave the surname, and put the initials on another line?
Thanks
Do you have the initials and surname in a string? Do you want to split the string?
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
post the code you're having trouble with.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
not got anything yet really. if i was to put it in a string how would i do that and then how would i spilt the string to do what i am wanting it do do?
>> not got anything yet really.
me neither.
>> if i was to put it in a string how would i do that and then how would i spilt the string to do what i am wanting it do do?
why don't you give it a try first and see what you come up with? after all programming *is* about problem solving, right?
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
> not got anything yet really
Apparently, you have the code which prints both on the same line.
How about you post that, then perhaps we can tell you how to change it.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
hi,
this is what i have
it manages to copy the first 3 letter whiich i want it to do, but i also want it to copy the remiaining letters onto another line.Code:char szname[50]; cout << "Please enter your initials and surname: "; char str2[3]; strncpy (str2,szname, 3); str2[3] = '\0'; puts (str2); cout <<endl; cin.getline(szname, 20);
eg.
user enter - AN Other
Output
AN
Other
can any one help with that?
Not really.Originally Posted by peckitt99
1) Move the cin.getline(szname, 20); immediately below the prompt and you have it.
2) Fix definition of str2 -- make it 4, not 3
3) Instead of puts(), use your cout
4) The rest of the string is at the address (&) of the 4th character ([3]) in szname. Put that together and output it.
[edit]And don't bump your threads -- it's not a good thing[/edit]
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
managed to do most of that but i dont understand 4.
4) The rest of the string is at the address (&) of the 4th character ([3]) in szname. Put that together and output it.
what do you mean?
Thanks for your help.
The first element of an array is [0]. The last element is [elements-1]. So if you have an array declared like this:4) The rest of the string is at the address (&) of the 4th character ([3]) in szname. Put that together and output it.
what do you mean?
the addressable elements are [0] to [2]. [3] is out of bounds.Code:int array[3];
If you take the address of array[1], like this:
it's like you have another array that starts at array[1] (of course, it's the same array, occupying the same memory). So if you haveCode:&array[1]
the output will beCode:char s[] = "hello world"; cout << &s[5];
which is what you want (&szname[3]).Code:world
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Hi,
Got it working thanks for all your help much appreciated!!
Thanks!!!