| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
The function you are looking for is in string.h and is strcpy -
strcpy (scratch, argv[1]); -KM- |
|
#3
|
|||
|
|||
|
hey
will strcpy work if i need to do the same thing only from a char array to an int array? |
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > need help with easy probelm for working around cin.getline |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|