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

strcpy() only copying one string to a struct, but not the other

I'll cut it down to the bare basics, as the rest of the code is unnecessary. It's a basic text adventure program. // defines numeric values for each room typedef enum { KITCHEN, PANTRY, HALLWAY_1, HALLWAY_2, TROLLS_DOMAIN, …
Sato
  • 115
  • 1
  • 1
  • 13
0
votes
1 answer

Copy string to element of struct array

I'm attempting to copy a C-string, which is read in from a file to an element of a struct array, but it is not copying. When I attempt to print, the word is not there. I'm kind of new to C. Below is my code. Many thanks for your help. typedef struct…
user5924094
0
votes
2 answers

conflict of using strcpy , strcat in C?

In the following code I'm trying to load a text file of words character by character then I'm trying to save each whole word in hash table (array of strings) but it seems that strcpy saves a whole word not a single char and I don't know why. Am I…
0
votes
1 answer

Segmentation fault strcpy

typedef struct Movie{ char hallName[50]; char movieName[50]; }movie; I have dynamically created movie array. In processCommand function: char *hallName; hallName = strtok(NULL," "); and call createHall function with this…
B.IS
  • 41
  • 6
0
votes
1 answer

C - Problems copying string from one struct to a node

I am trying to copy strings from a field in one struct to another struct (a node), so that I can ultimately create a hashtable. However, I seem to be having some issues in the actual string copying. I've created a for loop to iterate over the…
Allie H
  • 121
  • 1
  • 11
0
votes
1 answer

Deleting pointer causes heap corruption

Could somebody explain why this code results in heap corruption? string someText = "hello hello"; char **arrayOfCharPtr = new char*[5]; arrayOfCharPtr[0] = new char[someText.length()]; strcpy(arrayOfCharPtr[0], someText.c_str()); delete[]…
Johan
  • 863
  • 3
  • 13
  • 28
0
votes
2 answers

What is the underlying mechanism of char array[] = "string"?

I know that in C string assignment must go through char string[4]; strcpy(string, "aaa"); but why and how does C allow char string[] = "string"; ? Thanks in advance
Daniel Jee
  • 664
  • 5
  • 10
0
votes
1 answer

strcpy Crashes C Program

Please tell me why strcpy fails. Im trying to copy the value str1 into one of the element of str2. #include #include #include int main(int argc, char *argv[]) { char str1[]={"cat"}; //string char…
0
votes
1 answer

Influence of string length on uninitialized character pointer

The question is regarding "strcpy" using char pointer, which gives me segmentation fault. With a simple code below segmentation fault does not occur until no of characters in the string has reached 4 i.e "ZZZZ". why? CASE…
0
votes
1 answer

Segfault while accessing memory malloc'd in function

I'm trying to write a function that takes in a path (char *) and splits it into an array of strings based around the '/' delimiter. Simplified code below : int split_path(char * path, char ** out) { out = NULL; char * token = strtok(path,…
John Allard
  • 3,564
  • 5
  • 23
  • 42
0
votes
1 answer

EXC_BAD_ACCESS(code=1, address=0x0)

I'm trying to populate a linked list of structs from a global variable source and I get a BAD_ACCESS at the strcpy() line. Using C. Wondering if anyone could point out the issue. The global struct is declared as so: #include…
Darrell
  • 139
  • 7
0
votes
0 answers

Arguments on strcpy

So, I'm working on Binary Trees and I need to move information from one node to another one (structs). The thing is that I have this function that uses strcpy to copy the names and surnames from one node to other node (both sent as pointers) and…
0
votes
3 answers

Error in strcpy return not responding window

this code is a headstart to make a simple dictionary. im trying to insert the word and the meaning into array. what seems the problem? #include #include main(){ char alp, *a[5][1], item[100],item2[150]; for (int i =1;i…
Adam_Code
  • 25
  • 1
  • 10
0
votes
1 answer

write to shared memory segmentation fault

all I want to do is just write "hey" to my shared memory, but it gets thrown at that line. very simple code as follows: #include #include #include #include #include #include…
Zohar Argov
  • 143
  • 1
  • 1
  • 11
0
votes
2 answers

Segmentation fault after the inner of the struct disappear (variable corupted)

I have a very strange error on my code, which I run in VS 2015 and eclipse: int main(int argc, const char**argv) { FILE *input = stdin; FILE *output = stdout; if(!argumentsValid(argv, argc)){ mtmPrintErrorMessage(stderr,…
KittyT2016
  • 195
  • 9