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
-2
votes
2 answers

Abnormal behaviour of strcpy function in CodeBlocks with MinGW

strcpy function in CodeBlocks with MinGW is not behaving properly. It is modifying the constant string when the Destination has less space than source string. According to standards, if Destination has less space than source the behavior is…
skyconfusion
  • 123
  • 8
-2
votes
4 answers

Why is this simple piece of C code giving a segmentation fault?

#include #include #include int main() { int size_to_alloc = sizeof(char*) * 1; char** p = (char**) malloc(size_to_alloc); p[0] = (char*) malloc (sizeof(char) * 10); strcpy("hello", p[0]); …
amrka
  • 49
  • 1
  • 6
-2
votes
1 answer

Copy a string into 2D array of strings

I have a c code that tokenize the content of my file. I want to copy/assign each token to a temp variable to put it into a list. My temp was declared as char *temp[MAX]. Here is my code but there is something wrong in strcpy(temp[k], token). When i…
BoJack Horseman
  • 159
  • 5
  • 15
-2
votes
1 answer

strcpy and strcat return an error in c

char first[]="aa"; strcat(first,ar[0]); char *second[10]; strcpy(second[0],first); I want to use strcat and strcpy. strcat works but there is an error in strcpy. how can I modified it?
esrtr
  • 99
  • 2
  • 12
-2
votes
3 answers

Why the second strcpy() in my code causes stop working?

I wrote this C code: #include #include int main() { char *i, *p, *p1="Hello"; strcpy(p,p1); //The first strcpy works. printf("%s\n", p); //show copy successful printf("Please hit a key to continue....\n"); getchar(); …
Steve
  • 7
  • 2
-2
votes
2 answers

char * and char [] in strcpy

#include #include void main() { char str[] ="asdfasdf"; char *s; strcpy(s,str); printf("%s",s); } What's wrong with this code? Am I messing up with char* and char[]?
bulbasaur
  • 49
  • 1
  • 1
  • 6
-2
votes
2 answers

C implementention of strcpy does not change variable value

So, i am trying to implement my own strcpy to have a better understanding of how pointers work in C, and so far i am at a loss. I tried a lot of different approaches, tried using code from the net to maybe base mine on later, but even those wont…
Miyh0
  • 49
  • 1
  • 7
-2
votes
1 answer

strcpy access violation writing to a struct variable

I have a struct called record which contains key, value pair: struct Record{ char* key=new char(); TYPE value=NULL; Record(){ key = "default"; value = 10; } Record(const char* key_, TYPE value_){ …
Yochert
  • 85
  • 9
-2
votes
1 answer

I'm getting this error for strcpy

I'm getting these errors. On the first line and second line, it says No matching function for call to 'strcpy', i'm pretty sure im using the wrong preprocessor directive, I'm using #include < fstream> void writeStudents(vector
Huzaifa Imran
  • 11
  • 2
  • 2
-2
votes
1 answer

How to start the basic programming task using Pennsim and LC-3 programming language?

The task at hand is to write a subroutine STRCPY to implement a string copy function like the C the programming language's strcpy() function. I know: R1 is the address of the string to copy from R2 is the address of where the string is to be copied…
Jeremy
  • 7
  • 1
-2
votes
1 answer

the use of strcpy in C

okay, so basically ive been writing a program in the form of a tournament out of 16 players. I'm currently writing the code for the first round using loops and then attempting to send the winners of each match to a new array called R2CONTESTANTS.…
-2
votes
1 answer

How to collect variables with strcpy

I have some problems with collecting variables.. my current code: strcpy (date, year); strcat (date, "-"); strcat (date, month); strcat (date, "-"); printf("%s" , date); as result I would like to have 2014-04 for exsample, but currently it gives…
Tanhua
  • 39
  • 1
  • 5
-2
votes
3 answers

Joining 8 strings to form 1 string in C

I am doing a C programming school project. In one part of the project, I need to join every 8 strings (each 4 characters in length) to form 1 string (each 32 characters in length). For example, char *holdBinary[16] holds 16 strings such…
Begumm
  • 69
  • 1
  • 2
  • 11
-2
votes
2 answers

Segmentation fault (core dumped) error with strcpy() (suspected)

I am having trouble trying to this runtime segmentation fault in this short piece of code. I suspect it has something to do with the use of system() and strcpy() in the code but as I am not experienced with this type of error, I am unsure what to do…
jkrix
  • 15
  • 8
-2
votes
3 answers

How does strcpy() copy a string to an array when you can't change the address of an array?

So basically strcpy assigns the address of the 2nd argument to the 1st, but how does it do it with an array as the first argument? like in my program, i tried changing the address of the array but unfortunately it wont compile. So I had to resort to…
jantristanmilan
  • 4,188
  • 14
  • 53
  • 69