Passing Values problem

Vasconcelos
Vasconcelos used Ask the Experts™
on
the code copies a string to antother array of strings from one position to another and my problem is that i want to "push" it into a bidimensioal stack wich i made and im still new on pointers and i dont know how functions to pointers behave in this case with my push function.

best regards Vasconcelos.
char* str_cpy(char orig[], int pos1, int pos2, char dest[])
{
    int p = 0;
    p = pos1;
    while(p <= pos2){
        dest[p - pos1] = orig[p];
        p++;
    }
    dest[p - pos1] = '\0';
    return dest;
}
 
//and
 
void push(char* str, int t)
{
    int i = 0;
    if(top == MAXLINES)
    {
        printf("\nSTACK OVERFLOW");
        return;
        }else{
            for(i = 0; i < t; i++)
            {
                pilha[top][i] = str[i];
            }
    }
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
evilrixSenior Software Engineer (Avast)

Commented:
So, what is your question?

Author

Commented:
stacks,  pointers to functions etc...
evilrixSenior Software Engineer (Avast)

Commented:
Ok, but *what* is your question?

All you've done is state a requirement. What is it that you don't know or understand and need an answer too? Where in your code are you stuck?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:

for example i want to push a string
char* str_cpy(char text,  pos1, ipos2,  str)
i = strlen(str);

 push(str, i)  so what i wanna know if this is the correct way to push it or do i need to use a loop to push it char by char?

Author

Commented:
btw im sorry for the bad english its not easy since my native language is portuguese :)
Senior Software Engineer (Avast)
Commented:
Why not just use strncpy?

http://www.cplusplus.com/reference/clibrary/cstring/strncpy/
char * strncpy ( char * destination, const char * source, size_t num );

strncpy(pilha[top], str, i);
evilrixSenior Software Engineer (Avast)

Commented:
>> btw im sorry for the bad english its not easy since my native language is portuguese :)

That's ok... you are clear enough for me to understand... sorry my Portuguese is zero ;)

Author

Commented:
it was good

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial