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

After calling strcpy, the second char array becomes empty

Here is the function prototype in my program: void FindRepStr(char str[], const char findStr[], const char replaceStr[]); It find the findStr[] in str[] and replace it with replaceStr[]. Here is my code: void FindRepStr(char str[], const char…
BobHU
  • 402
  • 5
  • 18
-1
votes
1 answer

C strcpy crashes code

I have the following code, the code crashes whenever the strcpy function is called. When these lines are commented out the code does not crash. What is wrong? char cities[80][17]; char char_distances[40][2]; int distances[40]; char…
-1
votes
1 answer

c - struct unsafe warning

i am trying to use struct to make some kind of list that takes the student's name, number etc. My problem when i try to build solution and see if there is an error, compiler(Visual Studio 2013) tells me to use "strcpy_s" intead of "strcpy". And when…
simonJarr
  • 28
  • 7
-1
votes
3 answers

C segmentation fault using malloc'ed strings

Essentially, I have a structure for a linked list in my code, struct node{ char* val; struct node *next; }; Then later I try to do some things to it... ... addr = malloc(sizeof(struct node)); addr->val = malloc(72); addr->val =…
-1
votes
2 answers

Probleme when trying to store char[] into char*

I'm curently developping a web application in C on a Debian (don't ask me why). I made a method to get the data from a form using POST : const char* getParam(char* postResult, char* param) { char stock[30]; char* pointer = strstr(postResult,…
-1
votes
1 answer

In C, I'm unable to copy a single element of an array of character strings to another string

I have a string "prompt" that holds a string of characters. The user must be able to change the prompt with user input, which I've collected and separated (using whitespace as a delimiter) into an array of char strings (tokens). For example,…
-1
votes
1 answer

Multiple consecutive strcpy(), display contains bits of every next strcpy()

This is my code, for a machine project, I'm only in my first year in programming course (basic stuff). This is a pokemon battle simulator, and i' am merely setting the moves, and stats, of the pokemon, as to what the user decides what his pokemon…
Adrian Ty
  • 3
  • 2
-1
votes
1 answer

Unhandled exception at 0x5E10F1C0 (ucrtbased.dll) in HW 5 Rational pt2.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC. occurred

I'm confused why I am getting this error. I've looked around and have found someone with a similar error, and their issue was not allocating enough new memory for NULL. I didn't think that was the problem with mine, because I added strlen + 1? I'm…
Hanna369
  • 61
  • 5
-1
votes
1 answer

strcpy() error: Bad permissions for mapped region at address

I have a problem with exercise 5-13 of K&R, the goal of the exercise is to make a function tail that does the same as the *nix command, here's my function: #include #include #include "tail.h" int tail(int n) { char…
ColdCoffeeMug
  • 168
  • 1
  • 13
-1
votes
1 answer

Memory Error with structures in C

The code below deletes the contents of game.answer in the future and I can't figure out why. This is the structure: typedef struct { int guesses, guessesAllowed; char* answer; char max; } GameState; And this is my function to build a new…
Zach
  • 237
  • 4
  • 16
-1
votes
1 answer

copying a string in an array element of a struct

I have the following problem: I made this node structure typedef struct NODE{ struct NODE *sons[1024]; //this array will be used to store children pointers char name[255]; int leaf; }NODE; and this…
Speck
  • 21
  • 2
-1
votes
2 answers

strcpy: detected source and destination buffer overlap

This is my implementation of Conway's Game of Life. I'm currently trying to implement repetition detection, which allows the program to detect repetitions with periods up to 4 generations long. For this purpose, I use a list called statelist that…
Sahand
  • 7,980
  • 23
  • 69
  • 137
-1
votes
3 answers

faster way than memcpy to copy 0-terminated string

I have a question about duplicating a 0-terminated string: const char * str = "Hello World !"; size_t getSize = strlen(str); char * temp = new char[getSize + 1]; ... i know i can use this function memcpy(temp, str, getSize); but i want to use my…
myOwnWays
  • 59
  • 4
-1
votes
5 answers

When using strcpy() does the destination string need to be one element bigger than the source string?

Consider this code snippet (simplified syntax for clarity). void simple (char *bar) { char MyArray[12]; strcpy(MyArray, bar); } My instructor says that MyArray can copy at most 12 elements from bar, but from what I've read, MyArray can only…
Akhil Pothana
  • 21
  • 1
  • 4
-1
votes
2 answers

strcpy and sprintf in C

I'm trying to set some string variables like this: char thingA[7], thingB[7], thingC[7]; strcpy(thingA, "StringA"); strcpy(thingB, "StringB"); strcpy(thingC, "StringC"); printf("%s\n", thingA); printf("%s\n", thingB); printf("%s\n", thingC); but…
Matthew
  • 185
  • 1
  • 12