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

Strcpy resulting in segmentation fault

I'm not really sure why strcpy is resulting in a segmentation fault and was wondering if someone could explain to me why. I originally had temp->data = name but that resulted in the Node value changing every time I changed the name array and was…
antelemon
  • 55
  • 9
0
votes
1 answer

Why does strcpy work when array sizes are immutable, C

So I'm enrolled in a beginner level systems course at my university and my professor mentioned that array sizes cannot be changed because they are set in memory. Furthermore, that strings in C are just arrays of characters. So my question is, how…
JoshPark
  • 19
  • 7
0
votes
2 answers

Variable empty after comparison

In the code, when I print var_value, it shows its content but when I need to assign it later on the if else statements, it's empty only IN THE LAST IF and I have no idea why it is. If I delete the last statement, the other three pass without…
0
votes
1 answer

Why is reading from file function crashing?

Trying to read multiple line from file to store them in a structure made up of the string elements, however when I run the program it simply crashes and I haven't the faintest idea why. function in question: Hashtbl* loadfromfile(Hashtbl* hashtbl,…
John
  • 71
  • 1
  • 1
  • 10
0
votes
1 answer

strcpy() and/or strcat() hangs Arduino Uno

I have an Arduino Uno V3. The sketch I'm working on has a couple of global vars in which a file within a directory is stored which I want to playback on the Adafruit Music Maker shield. All is fine, as long as I just want to play the file which is…
siliconchris
  • 613
  • 2
  • 9
  • 22
0
votes
1 answer

XCode strcpy ( char *dest, io_name_t src) not copying to dest

This has to be a simple error on my part, hence why I use the term "not working" with hesitation. Here is my code, the problem is the strcpy from io_name_t variable to char array seems to not work, i.e. the data is not copied. Define the struct to…
TenG
  • 3,843
  • 2
  • 25
  • 42
0
votes
1 answer

malloc and strcpy interactions

I've been testing out interactions between malloc() and various string functions in order to try to learn more about how pointers and memory work in C, but I'm a bit confused about the following interactions. char *myString = malloc(5); // enough…
Prism
  • 53
  • 1
  • 4
0
votes
3 answers

copy a sub part of a string

I'm trying to copy a part of a string in a other string. I know the 2 identifiers starting and ending the sub-string. I'm trying to copy the IP from this string: 0x200085f6 "GET / HTTP/1.1\r\nHost: 192.168.1.200\r\nConnection The…
Dylan
  • 45
  • 1
  • 9
0
votes
1 answer

Merging strings together based on command line arguments.

I'm trying to write a program in C to merge 2 string together in two diffrent ways based on the given command line argument. '-i' to merge the string alternating, like this combine_strings –i Please enter a string of maximum 30 characters:…
Wilson
  • 1
  • 1
0
votes
2 answers

Weird Segmentation Fault when doing strcpy the 2nd time on the same string C

I am tokenizing lines of delimited by commas and since some titles have commas in them, they are surrounded by quotes. I tokenize up to the first quote, store it in fronttoken, then up to the 2nd quote, store it into title, and then finally I…
codemonkey
  • 58
  • 1
  • 8
0
votes
1 answer

Visual studio Run-Time Check Failure #2 - Stack around the variable 'temp' was corrupted

I've written a function to partition elements for a quick sort algorithm for sorting an array of cstrings void partition(char words[][MAXWORDLEN + 1], int start, int end, int& partitionIndex) { char pivot[MAXWORDLEN + 1]; //choose last element to be…
Howard Wang
  • 472
  • 6
  • 18
0
votes
0 answers

Message "program has stopped working" on function strcpy

I am New on pointers and I had and excercise where you had to get info from a txt file then put that info into an structure. anyways when I get the info and call de copyname() function the compiler seems to stop working. I have also checked if…
Dr Jfrost
  • 134
  • 10
0
votes
1 answer

Segmentation fault when calling strcpy

I was trying to use strncpy and then strcpy and vice versa, but I kept receiving a segmentation fault during runtime. I thought this was because of an logical error in the functions, but I switched their places and only the first one would execute.…
Gideon
  • 37
  • 1
  • 9
0
votes
2 answers

c strcpy a file descriptor

I have a question with strcpy() function. What I am trying to do is the user enters a file name and I basicly open the file, gets contents and create copy of file. However, I decided to do some error checking to check if the content read() is the…
daza166
  • 3,543
  • 10
  • 35
  • 41
0
votes
1 answer

What is wrong with the following strcmp() code?

I have a multidimensional array of a structure, whose content is initialized to '\0' initially and later occasionally. After some values are inserted, it is sorted on fing_print in an ascending order. Then the first n entries of the sorted array is…
George
  • 37
  • 8