yeah i got that but it is the last name that messes up when you output it all. the first name comes out fine but the last name dosnt it comes out in odd ascii charactures.
This is a discussion on Storing in an Array within the C++ Programming forums, part of the General Programming Boards category; yeah i got that but it is the last name that messes up when you output it all. the first ...
yeah i got that but it is the last name that messes up when you output it all. the first name comes out fine but the last name dosnt it comes out in odd ascii charactures.
My code works perfectly well. If you please post yours it will be easier to find what you are doing wrong.
my code is the same as yours i think but here it is anyway...
it also comes up with the first letter of the first name as the second nameCode:#include <iostream> #include <iomanip> int main() { using namespace std; char Fname[10]; char Lname[10]; char Fullname[20]; cout << "First name: "; cin >> Fname; cout << "Family name: "; cin >> Lname; int i = 0; while (Fname[i] != '\0') { Fullname[i] = Fname[i]; i ++; } Fullname[i] = ' '; i++; int j = 0; while (Lname[j] != '\0') { Fullname[i] = Lname[j]; j ++; } cout << Fullname << endl; system("pause"); }
Last edited by peckitt99; 10-09-2006 at 03:13 PM.
Oh, I had done a bracket typo in my code. It is functional now.
The reason it outputted strange characters was that I forgot to terminate the string with a '\0'. And I had forgot to increment i in the last loop. It is getting late.
so what is needed in the code?
yeah i think i got it thanx
Well I did update my code, so just check it. It should be really simple to understand as well.
now i need to re-do the program to show i can use strcyp() n strncat(), all fun
Why are you using c strings? Use std::string and all your problems will go away.Originally Posted by peckitt99
With strcyp() and strncat() anyway. That's what it's there for.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
I think he needs to do it with strncpy() and strncat() not with strings.
"The Internet treats censorship as damage and routes around it." - John Gilmore