Array[] from *ptr question

Discussion in 'C Programming' started by sjonca, Oct 14, 2003.

  1. sjonca

    sjonca Guest

    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 ;

    }


    --
    Posted via http://dbforums.com
    sjonca, Oct 14, 2003
    #1
    1. Advertising

  2. sjonca <> scribbled the following:
    > 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 ------------------------------------>

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "Holy Banana of this, Sacred Coconut of that, Magic Axolotl of the other."
    - Guardian in "Jinxter"
    Joona I Palaste, Oct 14, 2003
    #2
    1. Advertising

  3. Off Topic: Array[] from *ptr question

    sjonca wrote:

    > 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.
    E. Robert Tisdale, Oct 14, 2003
    #3
  4. sjonca

    sjonca Guest

    sjonca, Oct 14, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sid
    Replies:
    5
    Views:
    1,065
  2. Heiko Vogel
    Replies:
    3
    Views:
    548
    Method Man
    Sep 14, 2004
  3. franco ziade

    const ptr to const ptr ?

    franco ziade, Feb 17, 2005, in forum: C Programming
    Replies:
    3
    Views:
    387
    franco ziade
    Feb 17, 2005
  4. G Fernandes
    Replies:
    9
    Views:
    577
    DHOLLINGSWORTH2
    Feb 27, 2005
  5. hans christian

    newbie question: difference between (*ptr) and *ptr

    hans christian, Jun 11, 2006, in forum: C Programming
    Replies:
    5
    Views:
    722
    hans christian
    Jun 11, 2006
Loading...

Share This Page