strcpy Questions

11

Solved

Edit: I've added the source for the example. I came across this example: char source[MAX] = "123456789"; char source1[MAX] = "123456789"; char destination[MAX] = "abcdefg"; char destination1[MAX]...
Pga asked 11/8, 2009 at 5:17

6

Solved

I'm trying to understand how to solve this trivial problem in C, in the cleanest/safest way. Here's my example: #include <stdio.h> int main(int argc, char *argv[]) { typedef struct { char...
Gotland asked 28/6, 2010 at 9:35

6

Solved

I read that strcpy is for copying a string, and strdup returns a pointer to a new string to duplicate the string. Could you please explain what cases do you prefer to use strcpy and what cases do ...
Trilateral asked 24/12, 2012 at 10:53

7

Solved

I've been working on a project in C that requires me to mess around with strings a lot. Normally, I do program in C++, so this is a bit different than just saying string.empty(). I'm wondering wha...
Sigismondo asked 12/11, 2011 at 21:52

10

Solved

So, I have seen this strcpy implementation in C: void strcpy1(char dest[], const char source[]) { int i = 0; while (1) { dest[i] = source[i]; if (dest[i] == '\0') { break; } i++; } } ...
Cardoza asked 23/1, 2013 at 9:47

2

So I was reading Hacking the Art of Exploitation and in the book, they use the strcpy() function in their C code: 1 #include <stdio.h> 2 #include <string.h> 3 4 int main() { 5 char st...
Antoinette asked 20/1, 2019 at 23:0

9

Solved

In an interview, I was asked to write an implementation of strcpy and then fix it so that it properly handles overlapping strings. My implementation is below and it is very naive. How do I fix it s...
Dwyer asked 15/9, 2011 at 8:1

9

Solved

What is the difference between memcpy() and strcpy()? I tried to find it with the help of a program but both are giving the same output. int main() { char s[5] = { 's', 'a', '\0', 'c', 'h' }; cha...
Bagwig asked 24/5, 2010 at 16:9

2

Solved

In the following program, i intend to copy char* line contents from one object to another through strcpy. However when the program ends, destructor of obj2 works fine but dtor of obj crashes. gdb s...
Flannelette asked 25/11, 2019 at 15:6

5

Solved

I have an array of strings with a given size, without using any memory allocation, how do I append something into it? Say I run the code, its waiting for something you want to enter, you enter "bo...
Siphon asked 17/4, 2015 at 12:37

3

Solved

I know strncpy is a safer version of strcpy as said here. However, when I want to copy from src to dst and dst is not a clean buffer, I get unwanted results, which can be avoided by strcpy: char ...
Hagy asked 6/9, 2018 at 15:11

6

Solved

A lot of the functions from the standard C library, especially the ones for string manipulation, and most notably strcpy(), share the following prototype: char *the_function (char *destination, .....
Hehre asked 24/8, 2010 at 22:7

7

Solved

How do I copy a char* to a unsigned char* correctly in C. Following is my code int main(int argc, char **argv) { unsigned char *digest; digest = malloc(20 * sizeof(unsigned char)); strncpy(di...
Gravedigger asked 4/8, 2011 at 11:0

3

Solved

#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { const char* hello = "Hello, World!"; char *str = malloc(14 * sizeof(char)); for (int i = 0; i < 14; i+...
Eyre asked 14/5, 2018 at 21:38

6

Solved

When writing a project, I ran into a strange issue. This is the minimal code I managed to write to recreate the issue. I am intentionally storing an actual string in the place of something else, wi...
Testify asked 10/11, 2017 at 10:4

3

I have large project having strcpy used everywhere. I am thinking to use strcpy_s instead of strcpy. I think almost 10,000 times I have used strcpy. It's so cumbersome to change every strcpy. Is th...
Incise asked 3/5, 2017 at 9:31

4

Can someone please explain to me why strcpy() is necessary to assign strings to character arrays, such as in the following code snippet. int main(void) { char s[4]; s = "abc"; //Fails strcpy(s, ...
Guipure asked 1/8, 2011 at 15:58

5

Solved

Is there a reason strcpy's signature is this: char *strcpy(char *dest, const char *src); instead of this? char *strcpy(char *const dest, const char *src); As far as I know, the function will ...
Mither asked 23/1, 2017 at 16:19

3

Solved

I'm a beginner to C but I have this code running on xcode through gcc on terminal: #include <stdio.h> #include <string.h> int main(){ char name[12] = "Roman Mirov"; printf("My name...
Vow asked 27/12, 2016 at 7:15

2

Solved

I have a C++11 project, and I added some strcpy_s method calls. This works on windows, but when compiling on gcc, there is an error stating that strcpy_s symbol is not found. I did add the line #...
Boling asked 14/10, 2016 at 14:44

4

Solved

As we all know, strcpy_s is a safety version of strcpy. But I wonder how it works ... let's see some examples. strpy_s's declaration: errno_t strcpy_s(_CHAR *_DEST, size_t _SIZE, const _CHAR *_...
Koniology asked 26/4, 2014 at 5:58

1

Solved

Using the function strcpy in MS Visual Studio gives me an error saying I should use strcpy_s which is safer to use. Is strcpy_s part of the C++ standard? Or is it only part of Microsoft Visual C++?...
Nonjuror asked 8/4, 2016 at 4:44

5

I want to copy a null-terminated string to another location and want to know how long the copied string was. Efficiency is of utmost importance. There ist the strcpy function which can achieve this...
Laquitalar asked 21/12, 2015 at 19:12

1

Solved

I have a simple program going this: int main(void) { int fd; const char *text = "This is a test"; fd = open("/tmp/msyncTest", (O_CREAT | O_TRUNC | O_RDWR), (S_IRWXU | S_IRWXG | S_IRWXO) ); if...
Somatist asked 29/10, 2015 at 16:18

2

Solved

When I tried to use strcpy to copy a string it gave me a compile error. error C4996 'strcpy': This function or variable may be unsafe. Consider using `strcpy_s` instead. To disable deprecation, ...
Cocoa asked 21/8, 2015 at 8:51

© 2022 - 2024 — McMap. All rights reserved.