codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  how to refer strncpy parameters to function parameters?  mardc at 09:12 on Friday, August 19, 2005
 

I have a schoolproject in c++ where i need to
use a "person" struct. I instantiate 3 struct
members with the following line:


person pp1, pp2, pp3;

person *pp = new person; //somekind of allocation i tried
//in order to refer to the
//copyparam function in another cppfile

//The definition for the copyparam function.

person& copyparam(person&, person&)
{
strncpy(pp1, pp2, 20);
}
------------------------------------------
I need to use the strncpy function to copy
the contents of pp2 to pp1 and return a reference
for pp2. I really don't know how I should approach
this problem. And I hope that someone could help
me. i believe the line
strncpy(pp1, pp2, 20) is wrong but i don't really
know how i should refer to the parameters that
copyparam takes.

calls from the main program:

person

copyparam(pp1, pp2);
copyparam(pp1, pp2) = pp3;

please help me!

thank you.



  Re: how to refer strncpy parameters to function parameters?  Yusairi at 03:42 on Friday, August 26, 2005
 

some code to refer :-

// learn strncpy
int main(void)
{
char string[10];
char *str1 = "abcdefghi";

strncpy(string, str1, 3);
string[3] = '\0';
printf("%s\n", string);
return 0;
}

// learn struct
#include <string.h>
struct my_struct {
char name[80], phone_number[80];
int age, height;
} my_friend;

void func() {
strcpy(my_friend.name,"Mr. Wizard"); /* accessing an element */
}

struct my_struct my_friends[100]; /* declaring additional variables */


Yusairi: site expert
http://www.codetoad.com









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
• I Need Help
• User input validation
• Create a wrapper for a COM Dll
• HashMaps
• HashMaps
• NEED HELP! Urgent
• Re: Exciting Open Source Project in C++
• Re: The Ballarat Airline Company (BAC)
• Re: problem getting prompt window to work on IE


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2008