Questions tagged [strcpy]

The C standard library function, "strcpy()," is used to copy non-overlapping, null-terminated strings. It is also defined as "std::strcpy()" in the C++ standard library.

Used to copy null-terminated, non-overlapping strings, it is defined in the <string.h> standard header. It is also defined in the C++ standard library in the <cstring> header.

Documentation for C strcpy.

Documentation for C++ std::strcpy.

947 questions
1
vote
2 answers

Why segmentation fault on implementation of strcpy?

I implement a simple strcpy, but when i run it , it always give a segmentation fault. Please help! Below is my code: #include char* mystrcpy(char *dst, char *src){ char *ptr = dst; while (*src !='\0') { *dst = *src; …
1
vote
2 answers

Using strcpy() function in C

I am presently new to programming and am following the C language which is being taught to us in our College. I have doubt in the actual functioning of the strcpy() function under the header-file #include The general use of this function…
granthium
  • 111
  • 1
  • 4
1
vote
0 answers

Why in the prototype of strcpy() function one parameter is of constant type?

When we write the prototype of strcpy() function it goes like this - char *strcpy(char *s1, const char *s2); here the second parameter const char*s2 which is to be copied to s1 is of constant type . Why we take it as a constant ?
1
vote
3 answers

How to have a call function as the second string in strcpy?

I need to call a function from the main to determine a string value. However, as far as I know, string cannot be in the form string_name = call_function(). The assignment of string has to be in form of strcpy(str1, str2) right? So I am wondering…
1
vote
2 answers

Segmentation fault on strcpy even though I am using malloc

I am trying to make a Doubly Linked List in C. And I get a Segmentation Fault even though I use malloc. Here is my code so far. list.h #ifndef _LIST_ #define _LIST_ typedef struct listnode { char * data; struct listnode * next; struct…
1
vote
3 answers

When does a while loop stop when it reads a string in C?

I'm trying to implement the strcpy function by myself. The original strcpy is part of the the string.h library. char *strcpy(char *dest, const char *src) { assert(dest != NULL && src != NULL); char *temp = dest; while (*src) { …
NoobCoder
  • 513
  • 3
  • 18
1
vote
1 answer

Trying to use the strcpy_s in vsc?

When I try to run the code i get: warning: implicit declaration of function 'strcpy_s' [-Wimplicit-function-declaration] I included string.h and stdio.h. Code: #include #include int main(void) { static int foo = 0; …
1
vote
2 answers

C strcpy() to a Pointer? How does this work?

This is an example from a book I am reading, to demonstrate the use of heap memory. #include #include #include int main(int argc, char *argv[]) { char *char_ptr; int *int_ptr; int mem_size; if (argc…
raincouver
  • 61
  • 7
1
vote
0 answers

Doing buffer overflow attack without knowing buffer size and address

I was trying to solve SEED security lab regarding buffer overflow attack but in that exercise we get buffer address and ebp and thus offset of it. so we are able to guess where the return address is stored. I know that without getting ebp and…
John
  • 33
  • 10
1
vote
2 answers

strcpy problem with two dimension array in C

I'm trying to copy a string to an array of strings using the strcpy function but it doesn't work! Here is the code: char *message[10] = { "Hello!000000000000", "Good Bye!", "1202", "hel", "beh", "cheshm" }; char *dst = "Copy"; strcpy(&(message[0]),…
GHOST mHBr
  • 15
  • 4
1
vote
1 answer

Can I strcpy a char pointer into another without allocating the second one?

I want to copy one char * string into another char * variable so I have the same string stored twice into those two char * variables but that they do not depend on each other, so if I make a free of the first one, I don't lose the data on the second…
1
vote
0 answers

Determine type of first argument in a call to strcpy(): (char *) vs char[]

I have been given a C program with about 20.000 calls to the library function strcpy. In the program, the type of the first argument (the destination buffer) passed to strcpy is declared sometimes as a (char *), sometimes as a char[]. Actually my…
bandolero
  • 21
  • 1
1
vote
1 answer

Memory Allocated But Can't Be Freed C

I am currently working on a project in C where my goal is to create a an array of strings, and fill them all with words from a file (Currently I just explicitly insert a string). #include #include #include int…
1
vote
1 answer

Need guidance with aspects of strcpy in C

This code is from strcpy in string.c I am trying to understand a few of the features here: char *(strcpy)(char *restrict s1, const char *restrict s2) { char *dst = s1; const char *src = s2; while ((*dst++ = *src++) != '\0') …
user10538922
1
vote
0 answers

Why do I get error "was not declared in this scope"

This is a part of my code where I get two errors: void Person::setName(char* n) { Name = new char[strlen(n) + 1]; strcpy(Name, n); } main.cpp:217:26: error: ‘strlen’ was not declared in this scope Name = new char[strlen(n) +…
user13563816