Array[] from *ptr question

S

sjonca

I have the need to convert from a *ptr to an array[]. I'm using the
getpass(x) function that returns a *ptr. I want this converted to an
array[] in order to concatonate it with 4 other array[] strings. Here's
a snippet of the class created. Any help would be appreciated.



#include <iostream.h>

#include <string.h>

#include <math.h>

#define Space " "



class PassWD

{

public:

char *return_passwd() ;

char passwd(char *X, int) ;

char *oldp, *firn, *secn ;

};



char PassWD::passwd(char *X, int num) //the *ptr is required and

{ //from the
getpass() func

if(num==1) { //the num is an arg
sent

strcpy(oldp,X) ; } //to delineate the
difference

else if(num==3) {

strcpy(firn,X) ; }

else if(num==5) {

strcpy(secn,X) ; }

return 0 ;

}



char *PassWD::return_passwd()

{

char *Newp = new char[50] ;

strcpy(Newp,oldp) ;

strcat(Newp,"/") ;

strcat(Newp,firn) ;

strcat(Newp,"/") ;

strcat(Newp,secn) ;

return Newp ;

}
 
J

Joona I Palaste

sjonca said:
I have the need to convert from a *ptr to an array[]. I'm using the
getpass(x) function that returns a *ptr. I want this converted to an
array[] in order to concatonate it with 4 other array[] strings. Here's
a snippet of the class created. Any help would be appreciated.

In C, when used in a value context, arrays and pointers work in the same
way. So I suspect you only *think* you need to convert pointers into
arrays, when you do not really need to.
#include <iostream.h>
#include <string.h>
#include <math.h>
#define Space " "
class PassWD
{
public:

Oops. We're no longer talking in C, are we?
comp.lang.c++ is that way ------------------------------------>
 
E

E. Robert Tisdale

sjonca said:
I have the need to convert from a *ptr to an array[].
I'm using the getpass(x) function that returns a *ptr.
I want this converted to an array[]
in order to concatonate it with 4 other array[] strings.
Here's a snippet of the class created.
Any help would be appreciated.

#include <iostream.h>
#include <string.h>
#include <math.h>

#define Space " "

class PassWD {
public:
char *return_passwd(void);
char passwd(char *X, int);
char *oldp, *firn, *secn;
};


char PassWD::passwd(char *X, int num) { //the *ptr is required and
//the *ptr is required and from the getpass() func

if(num==1) { //the num is an arg sent
strcpy(oldp, X); } //to delineate the difference
else
if(num==3) {
strcpy(firn, X); }
else
if(num==5) {
strcpy(secn, X); }

return 0;
}

char *PassWD::return_passwd(void) {
char *Newp = new char[50];
strcpy(Newp, oldp);
strcat(Newp, "/") ;
strcat(Newp, firn) ;
strcat(Newp, "/") ;
strcat(Newp, secn) ;

return Newp ;
}

Post to comp.lang.c++ instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top