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
3 answers

Abort trap: 6 in C when using strcpy on MacOS

I am working on some code takes a string as input and returns it reversed. When I input a string, I get an "abort trap: 6" error. I think the issue is in my use (misuse?) of strcpy, but GDB is not being helpful and other questions on SO about this…
Luciano
  • 493
  • 5
  • 14
1
vote
1 answer

What is the difference between strcpy and "="?

I would like to know if there is a difference between char* test = "test" and strcpy(test, "test"), and if there is one, what is this difference. Thanks.
iAmoric
  • 1,787
  • 3
  • 31
  • 64
1
vote
1 answer

Copy global char** in a new char**

char * seleccion[5]={" "," "," "," "," "}; char **armar_Equipazo() { char** equipo= (char **)malloc(sizeof(seleccion)); for(int i =0 ; i<5 ; i++) strcpy(equipo[i],seleccion[i]); return equipo; } I need copy a char ** in a new…
1
vote
2 answers

strcpy() not working on some strings but not others

I'm trying to write a simple text adventure program in C. I'm having an issue with strcpy() when trying to set the name/description of each room in the game (see room_setup()). It sets the name/description for every room except for the first two…
Sato
  • 115
  • 1
  • 1
  • 13
1
vote
2 answers

Using strcpy on a dynamic array

I have got a basic question about the following code: int main() { char *sNext1="DABCD"; char Tmp[]=""; strcpy(Tmp, sNext1); return 0; } There is a error happened in "strcpy" when I run it. It seems that it doesn't allow me to copy…
Andy Lu
  • 29
  • 1
  • 7
1
vote
1 answer

Stack Smashing while using strcpy and strcat

I've been trying to debug this for a while, still can't figure out why this causes a stack smashing error (I think the error code is 6, or abort. Essentially this function takes a directory, opens a file and then puts that file into a function so it…
1
vote
2 answers

My implementation of strcpy not working properly

I've just written my strcpy function but it doesn't work properly. After x amount of characters I have an infinite loop or it will copy my string but give me an error... char *ft_strcpy(char *dest, char *src) { int i; i = 0; …
Tóth Attila
  • 149
  • 1
  • 1
  • 10
1
vote
1 answer

Segmentation fault with char array member of struct using strcpy()

I have a struct TREE defined this way: typedef struct TREE { NODE *head; } TREE; and a struct NODE defined as: typedef struct NODE { char boss[30]; char name[30]; struct NODE *firstChild; struct NODE *secondChild; struct…
Nick
  • 95
  • 8
1
vote
2 answers

strcpy and strcat in Keil C compiler

I used this code to print some string,but it does not print any thing.What is the problem? char* getNotFilledEncryptionParams(void) { char* nofilledStr; char tmp[3]; const char * arr[]= {" P,"," Q,"," A,"," B,"," C,"," R,","…
Hamid
  • 1,493
  • 2
  • 18
  • 32
1
vote
1 answer

C modify char** with strcpy

I'm a little bit confused with pointers at the moment, could someone explain to me the reason why attempting to change a char** with strcpy() causes a segmentation fault? void *change_string(char **string) { char *add = "Changed!"; strcpy(*string,…
tim
  • 33
  • 3
1
vote
2 answers

How can i overcome "unsafe" error?

I'm working on a project that is basically controlling a parking lot. And in some point of my code I use the function strcpy(), but I am getting an error saying that this function may be unsafe. Here's the part of the code I'm using…
César Pereira
  • 249
  • 4
  • 17
1
vote
3 answers

Return a string but get garbage

I'm trying to return a string from a function like this: virtual const char* what() const throw() { std::string str = "Name Error: name "; str+= n_name; str += " is not defined"; char ret[256]=""; const char* temp =…
1
vote
1 answer

Concatenating char arrays together

This is something I would have considered trivial several years ago... It's been awhile since I've dabbled in C or C++ and I'm having an issue that is now causing a migraine. I am receiving an error for the following…
user0000001
  • 2,092
  • 2
  • 20
  • 48
1
vote
2 answers

using strcpy() with strtok

I am attempting to split a line read in from a file and copy the data I found into a character array using strcpy() I understand that strcpy() needs a null terminating character at the end of the line otherwise it will seg fault, although I have…
1
vote
1 answer

Writing strings to dynamically allocated array

I keep getting 4 "Passing argument 1 of strcpy makes pointer from integer without a cast" error message each time I am trying to write a string to a dynamically allocated array of strings. I know that it has to do with my strcpy call obviously, and…
Dpry12
  • 105
  • 8