Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
help with strncpy

 
Post new topic   Reply to topic Printable version
 View previous topic  A Cicular Queue Utility Written in C Post :: Post c# timers  View next topic  
Author Message
hellzlaker
Registered Cap Buster
Popping men in the ass since Oct 2005


Gender: NEVER ENOUGH!
Joined: Oct 27 2005
Posts: 34
Offline

PostPosted: Sun Aug 24, 2008 6:49 pm    Post subject: help with strncpy Reply to topic Reply with quote

Im working on something that if you type it, and it finds it in data and says something, but its not working

Code: Show/Hide
                string data="fuck";
                string input;
                cout<<"enter :";
                cin>>input;
               
                int input2 = (int)strncpy((char*)input.c_str(),data.c_str(),sizeof(data));
               
                if(input2==0)
                {
                                                                          cout<<"woo u said fuck";_P;
                }
also im trying to make something that you type a whole sentence like "hello jimmy how are you" and if it finds word jimmy it says something back
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address MSN Messenger
Bak
?ls -s
0 in


Age:19
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Sun Aug 24, 2008 10:52 pm    Post subject: Reply to topic Reply with quote

strncpy does string copy (cpy = copy)

if you want to compare strings do strncmp (cmp = compare)

if you want to find a substring do strstr
_________________
SubSpace Discretion: A Third Generation SubSpace Client
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Snrrrub
Novice


Joined: May 29 2008
Posts: 37
Offline

PostPosted: Mon Aug 25, 2008 10:03 am    Post subject: Reply to topic Reply with quote

More importantly, you're using C++'s std::string class so you should avoid functions like strcpy and strcmp entirely. Instead of using strcpy, use the assignment operator (str1 = str2) and instead of strcmp, use the equality operator (if (str1 == str2)).

I strongly recommend using std::string instead of C-style strings where possible - you'll significantly reduce the likelihood of errors and you'll waste less time writing repetitive code.

-Snrrrub
Back to top
View users profile Send private message Add User to Ignore List
hellzlaker
Registered Cap Buster
Popping men in the ass since Oct 2005


Gender: NEVER ENOUGH!
Joined: Oct 27 2005
Posts: 34
Offline

PostPosted: Mon Aug 25, 2008 11:26 pm    Post subject: Reply to topic Reply with quote

What should I use from the C++ std::string if I would like a program to find a string from a string

for an example:

user types in a sentance hello my name is john
program looks if user said hello and if he did it says hello john
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address MSN Messenger
k0zy
Server Help Squatter


Gender:Gender:Male
Joined: Jan 11 2003
Posts: 571
Location: Germany
Offline

PostPosted: Tue Aug 26, 2008 3:16 am    Post subject: Reply to topic Reply with quote

find

http://www.cplusplus.com/reference/string/string/find.html
_________________
It's a shark! Oh my god! Unbelievable!
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Non-Subspace Related Coding All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 91 page(s) served in previous 5 minutes.

phpBB Created this page in 0.060459 seconds : 30 queries executed (50.4%): GZIP compression disabled