473,322 Members | 1,614 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,322 software developers and data experts.

How to copy string at specified memory location?

I have a string and i want to copy at specified memory location.
Suppose i have a pre-allocated memory represented by

char* logFile (unsafe code)

I have a generated string which contains the name of log file.
I want to copy that string on location represented by char*.

Please help me on this.
================================================== ===========

Also i have to copy specified number of characters from a given location
to specified location.

The code in delphi looks something like:

StrLCopy(msg, PChar(gsRootErrorMsg), MAX_ERR_MESSAGE);
where msg is character pointer:msg: PChar
and gsRootErrorMsg is string.


Help would be really appreciated.
Thanks.
Jan 13 '11 #1
3 3013
I can try to help, but you will need to help me understand this StrLCopy thing.

This is what i can guess it does.
StrLCopy(dest, source, number)

StrLCopy copies the first 'number' of characters from the string specified as 'source', to the 'dest' string

Am i right? If so, i can help, otherwise a little more explanation please.
Jan 14 '11 #2
No

Destination and source are memory locations.
So StrLCopy will copy the max number of characters from the memory address of source to memory address of destination.
Jan 14 '11 #3
GaryTexmo
1,501 Expert 1GB
I did some digging on this... I'm not sure how to get the memory address of a string in C# since it seems you can't get the address of a managed type.

That said, you can use a char array... Have a look at the following:

Expand|Select|Wrap|Line Numbers
  1.             string str = "blah";
  2.             char[] b = new char[str.Length];
  3.             str.CopyTo(0, b, 0, str.Length);
  4.  
  5.             foreach (char c in b)
  6.                 Console.Write(c);
  7.             Console.WriteLine();
  8.  
  9.             unsafe
  10.             {
  11.                 fixed (char* p = b)
  12.                 {
  13.                     Console.WriteLine((int)p);
  14.                     *p = 'f';
  15.                 }
  16.             }
  17.  
  18.             foreach (char c in b)
  19.                 Console.Write(c);
  20.             Console.WriteLine();
Have a read here: http://www.codeproject.com/KB/cs/csunsafeintro01.aspx

Also, here's some discussion on a C# equivalent of memset: http://stackoverflow.com/questions/1...of-memset-in-c
Jan 14 '11 #4

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

Similar topics

10
by: fabio de francesco | last post by:
Hi what do you think of the following? Why are we permitted to do that? And why the C++ Library doesn't stop someone willing to perfom that assignement (*a = 20)? #include <iostream> ...
11
by: William Buch | last post by:
I have a strange problem. The code isn't written by me, but uses the qsort function in stdlib. ALWAYS, the fourth time through, the memory location of variable list (i.e. mem location = 41813698)...
7
by: Ivan | last post by:
Hi how can I access the contents of a memoy location say at address 0x3FF in C? I tried this but didn't work unsigned int *wVal = 0x3FF; x = *wVal;
3
by: Chucker | last post by:
Hi Folks! For some reasons, this code: > float tmp = 0.; > for (int i = 0; i < 2000; i++) { > for (int j = i; j < 2000; j++) { > for (int k = 0; k < 9000; k++) {...
3
by: Cleo | last post by:
How would I hard code a certain variable to be stored in a specific memory location in a processor. When I declare a variable in my program, the linker automatically determines a location and assigns...
9
by: Alan T | last post by:
Is it possible to copy a file from one location to another? eg. from C:\Temp\Document\TestDoc.doc to C:\Deploy\Document\TestDoc.doc
3
by: MLH | last post by:
Say I have a string value in Access - perhaps "ABCDE". How do I copy it to Windoze clipboard? This is not a repost, but is related to a 7/26/06 post entitled "Probs running DoCmd.RunCommand...
1
by: michigaki | last post by:
Hi, we're currently working on a video streaming app. Here is the problem: int ConvertRGBtoYUV(int w, int h, unsigned char *rgb, unsigned int *yuv) { unsigned int *uu, *vv, *u, *v; unsigned...
2
by: Pawel | last post by:
Hallo. I have the following problem. I am debugging large code I am not familiar with. I noticed that memory location, for example funnyObject.field, changes somewhere and I do not know where,...
4
by: rn5a | last post by:
Is it possible to practically see the memory location stored in a variable? For e.g. consider the statement Dim myInt As Integer = 10 If I am not wrong, the memory location allocated to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.