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

strcpy anamoly, underfined behaviour

#include int main() { char *s; strcpy(s,"asdqw"); strcpy(s,s+2); return 0; } This program is not showing up any error when run in linux system, it works fine. But when on running in mac osx, it is showing abort trap :…
Aswin Prasad
  • 407
  • 6
  • 14
1
vote
1 answer

Using struct and strcpy, program crashes

Hello this is my first time posting on this site and also I am not very familiar with structures or with strcpy() I was wondering why my program below is crashing. #define _CRT_SECURE_NO_WARNINGS #include #include struct…
MasterDNE
  • 67
  • 1
  • 8
1
vote
3 answers

puts() displays the whole content of strcpy even if an overflow of dest occurs

After creating a char array of size 5, then I use strcpy to fill the contents of the array but with a string larger than the original size; then I use puts() to display the contents of the array an the whole string is displayed which is odd because…
Omar Muñoz
  • 59
  • 1
  • 5
1
vote
1 answer

strncpy To strcpy Equivilence in Code

I have this ugly function, and I feel that the entire strncpy should just be an strcpy: void PackData(char*& cursor, const std::string& data) { *(reinterpret_cast(cursor)) = static_cast(data.length() + 1); cursor +=…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
1
vote
1 answer

Is It Legal to Cast Away the Sign on a Pointer?

I am working in an antiquated code base that used unsigned char*s to contain strings. For my functionality I've used strings however there is a rub: I can't use anything in #include in the old code. Copying from a string to an unsigned…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
1
vote
2 answers

using strcat more than 1 time - link2019

I'm trying to use strcat 2 time in a row. when I compile first 2 lines it's works, but when I added the third line I get: "Error LNK2019 unresolved external symbol _srtcat referenced in function _StartUpFunc " strcpy(msg2sent,…
john
  • 45
  • 10
1
vote
2 answers

how to add String by value and not reference

Im making a really simple TODOlist in C. My add function takes a char * as its parameter. When I add it to my char ** list of reminders, it adds the memory address of my buffer instead of the value of the string. The problem becomes apparent when I…
1
vote
3 answers

String pointer array in C and strcpy

#define null "null" //its declared on top int hash_size=100; char *hash_table[hash_size]; int i; for(i=0;i
1
vote
0 answers

I don't know where's the error. C/C++

Hello everyone I have this code: #include #include #include #include struct ficha{ char dni[9]; char nombre[20]; char p_apellido[20]; char s_apellido[20]; char telefono[9]; }; ficha…
1
vote
4 answers

copy string to char**

I do not understand why the following code: char** receive_message(char** ret) { char* temp = "text"; strcpy(&ret, temp); return ret; } gives this error: warning: passing argument 1 of ‘strcpy’ from incompatible pointer type [enabled…
Mari
  • 35
  • 3
1
vote
1 answer

Segmentation Fault with strcpy in C

I've this struct: struct _window{ int bcolor; /* background color */ int fcolor; /* foreground color */ int x; /* x coordinate */ int y; /* y coordinate */ int sx; /* lenght */ int sy; /* high*/ char **matrix; /* Matrix with chars */ }; I use this…
1
vote
1 answer

difference between char [] and char* when doing strcpy

I have the following code, I wonder what is the difference between the implementation of str2 and str3, they both give the same results, which one is more prone to errors? EDIT: when I was testing the representation of str2, I have found that one…
Samer
  • 1,923
  • 3
  • 34
  • 54
1
vote
1 answer

C strcpy and strcat

I have a question about strcpy and strcat. In the program I'm trying to make I need to get the year someone was born from a fiscal code. The fiscal code is given as a char from a serial port, strcpy(temp, code[6]); strcat(temp, code[7]); yyyy = 1900…
parmigiano
  • 95
  • 1
  • 14
1
vote
2 answers

Combine characters from a two dimensional array into a string in C

I'm still new to programming but lets say I have a two dimensional char array with one letter in each array. Now I'm trying to combine each of these letters in the array into one array to create a word. So grid[2][4]: 0|1|2|3 0 g|o|o|d 1…
Yitzak Hernandez
  • 355
  • 4
  • 23
1
vote
2 answers

Why is a string copy function just assigning the pointer not working?

Consider this implementation of strcpy: void my_strcpy(char target[], char source[]) { target = source; } int main(void) { char target[20]; char source[] = "Source String"; my_strcpy(target, source); printf("Target: %s", target); …
User314159
  • 7,733
  • 9
  • 39
  • 63