User-defined string functions

User-defined string functions

Question:
I am moving from other languages to Visual C++. I am trying to write a function that returns a string (or pointer to a string), which will then be put into a buffer using the lstrcpy function. I get only the first letter.

Answer:
Please folks, if you ask questions like this, please include a very brief snippet of code. The problem is that pointers and strings work just fine, so you probably have a simple problem with your syntax. Unfortunately, I can only guess at what that might be.

Unless you are using some sort of string class, string pointers are declared as character pointers (char *). To have a function return a pointer to a string, it should be declared as returning char *. If you got that far, then the issue is probably how to assign to that return value. Some beginners might be attempted to do something along the lines of this:

char *GetString(){   char s[80];   strcpy(s, “Here’s a sample string!”);   return s;}
This routine declares a character array, copies a string to it, and then returns a pointer to that array. The problem is that the array is declared local to the function, which means it is deleted as soon as the function returns. So the pointer returned is not safe to use. Instead, the array should be declared as static or outside of the function.

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved