473,386 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

mem copy help need

63
Expand|Select|Wrap|Line Numbers
  1. main()
  2. {
  3. char *sou;
  4. char *dest;
  5. char str[4]={"ie"};
  6. char str1[4]={"ee"};
  7. int size;
  8. dest=&str;
  9. sou=&str1;
  10. printf("%s\n",sou);
  11. printf("%s\n",dest);
  12.  size =strlen(str);
  13. printf("%dsize\n",size);
  14. memcpy(dest,sou, size);
  15.  
  16. printf("%s",*sou);
  17. printf("\n%s",*dest);
  18.  
  19. }
  20.  
i couldnt copy the strings...pls help
Apr 2 '07 #1
1 1416
horace1
1,510 Expert 1GB
sou and dest are char* so you don't need the * to dereference them in the printf statement
Expand|Select|Wrap|Line Numbers
  1. printf("%s",*sou);
  2. printf("\n%s",*dest);
  3.  
also strlen() returns the number of characters in the string not counting the terminating null so you need to add 1 to size, e.g.
Expand|Select|Wrap|Line Numbers
  1.  size =strlen(str)+1;
  2. printf("%dsize\n",size);
  3. memcpy(dest,sou, size);
  4. printf("%s",sou);
  5. printf("\n%s",dest);
  6.  
Apr 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
4
by: away | last post by:
1. When a class defined with a member of pointer type, it's necessary to have a copy constructor and assignment operator. If don't pass objects of such class as value in a function and don't do...
14
by: MSR | last post by:
I have a couple of questions. 1. Copy Constructor. class A { private: int a1; double d1; char *ptr;
19
by: davidgordon | last post by:
Hi, I need some pointers/help on how to do the following if it possible: In my access db, I have the following: Tables: Products, Sub-Assembly, Product-Pack Table, Products
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
10
by: utab | last post by:
Dear all, So passing and returning a class object is the time when to include the definition of the copy constructor into the class definition. But if we don't call by value or return by value, ...
7
by: pallav | last post by:
I'm having some trouble with my copy constructor. I've tried using gdb to find the bug, but it seg faults in the destructor. I'm not able to see what I'm doing wrong. Since I'm using pointers, I...
22
by: clicwar | last post by:
A simple program with operator overloading and copy constructor: #include <iostream> #include <string> using namespace std; class Vector { private: float x,y; public: Vector(float u, float...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.