| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon May 28, 2007 12:24 pm Post subject: strcmp and strcat commands? |
|
|
| Code: |
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char name[50];
char lastname[50];
char fullname[100];
cout<<"Please enter your name: ";
cin.getline ( name, 50 );
if ( strcmp ( name, "Julienne" ) == 0 )
cout<<"That's my name too.\n";
else
cout<<"That's not my name.\n";
cout<<"Your name is "<< strlen ( name ) <<" letters long\n";
cout<<"Enter your last name: ";
cin.getline ( lastname, 50 );
fullname[0] = '\0';
strcat ( fullname, name );
strcat ( fullname, " " );
strcat ( fullname, lastname );
cout<<"Your full name is "<< fullname <<"\n";
cin.get();
}
|
Ok, in my tutorial in C++ we're working on strings, but, I don't get what strcat and strcmp do? I have run this program to see what it does, but I don't know why it does what it does. The website didn't really teach me what cin.getline() does. And it didn't explain WHAT strcat and strcmp does. Can someone help me with this?
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Mon May 28, 2007 12:57 pm Post subject: |
|
|
strcmp compares s2 and s1 and strcpy copies s2 to s1
Last edited by appalsap on Mon May 28, 2007 1:44 pm; edited 1 time in total |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon May 28, 2007 1:33 pm Post subject: |
|
|
| appalsap wrote: | | strcat appends s2 to s1 and strcpy copies s2 to s1 |
I said strcmp not strcpy...and what do you mean s2 and s1?
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon May 28, 2007 2:22 pm Post subject: |
|
|
Thank you!
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
|