C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 20th, 2004, 02:39 PM
dapatient dapatient is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 1 dapatient User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
need help with easy probelm for working around cin.getline

I have a program (encrypt.exe) that waits for user input using cin.getline()
to my understanding, cin.getline will take the input and parse it out over an array.

so for example lets say i run the program and it asks for text...
it type in "test"

my progarm will basically do this:
scratch[0] = 't';
scratch[1] = 'e';
scratch[2] = 's';
scratch[3] = 't';
scratch[4] = '\0';

Now what i want to do is avoid having the user input text by passing the text through the command line.
I am using main(int argc, char **argv) to do this.
so if i run the program like this... encrypt.exe test
i want it to do the same as above.
but the problem is "test" is entered in as one long char into argv[1].

how can i parse argv[1] to scratch[] so i get the same result as above... i.e.
scratch[0] = 't';
scratch[1] = 'e';
scratch[2] = 's';
scratch[3] = 't';
scratch[4] = '\0';

i know i can probably write some simple loop...but what fucition do i use to parse argv[1]?

i hope i made my probelm clear.

Thaks guys

Reply With Quote
  #2  
Old December 20th, 2004, 06:15 PM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
The function you are looking for is in string.h and is strcpy -

strcpy (scratch, argv[1]);

-KM-

Reply With Quote
  #3  
Old January 11th, 2005, 12:34 PM
maxmax maxmax is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 14 maxmax User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 17 sec
Reputation Power: 0
hey
will strcpy work if i need to do the same thing only from a char array to an int array?

Reply With Quote
  #4  
Old January 14th, 2005, 07:36 AM
maxmax maxmax is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 14 maxmax User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 17 sec
Reputation Power: 0
Exclamation

i have two integer arrays, temp_guess1] and guess[4], with temp_guess[1] being a four digit number, and i want to parse the four digit number from temp_guess[1] into guess[1], [2], [3], and [4]. i tried strcpy (guess, temp_guess[1]); but when i compile it i get an error which says "error C2664: 'strcpy' : cannot convert parameter 1 from 'int [4]' to 'char *'". at first i thought it meant that it couldnt convert an int to a char but both of my arrays are int. im not really familiar with the strcpy function, am i doing something wrong? if anybody can help, it will be greatly appreciated.

thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > need help with easy probelm for working around cin.getline


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT