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

(C) Getting segmentation fault on pointer strcpy

I am new to C and I have been stuck on this code for the whole moring. It compiles without a problem, but fails when executed. If you have any idea that would help me solve this, please leave me a comment. Any comment would be greatly…
seungyun
  • 88
  • 4
0
votes
0 answers

Segmentation fault caused by strcpy to an initialized variable

I am expanding the kilo text editor to include copying-and-pasting. I am getting a segfault, which I have narrowed down to be because of a strcpy. I am using a typedef to store information about the marking. Here's that typedef, as well as where…
ARI FISHER
  • 343
  • 1
  • 13
0
votes
0 answers

How can i copy data from struct or union to buffer array without null chars?

I am coping conf data from struct to char array buffer.Data copied successfully but problem is that null also copied from structures because of size. How can i get data without null. #include #include #include…
voidpointer
  • 301
  • 1
  • 8
0
votes
3 answers

Program Prints the string in the wrong way. strcpy

After I put the input for name and surname (example: name:Mario surname:Rossi) As an output instead of getting Mario Rossi I get ossi Rossi but I can't understand why. int main() { char space[] = " "; char name[40], surname[40],…
Leit22
  • 13
  • 3
0
votes
2 answers

When insert string values into a char list by char, why do we use length + 1?

When I want to give an input from user as string, then insert each char into a new list, I use the commands below: #include #include #include using namespace std; int main() { string text; cout<<"Text: "; …
user12503185
0
votes
6 answers

Turbo C strcpy library function

I discovered that the strcpy function simply copied one string to anther. For instance, if a program included the following statements: char buffer[10]; ---------- strcpy(buffer, "Dante"); the string "Dante" would be placed in the array buffer[].…
Aaron
  • 1,969
  • 6
  • 27
  • 47
0
votes
1 answer

C: copy string into list of strings

So I have a list of names and corresponding phone numbers, and I want the user to be able to continuously enter a new name-number pair into that list. The part of my code where I try to do that looks something like this: char name[20],…
0
votes
1 answer

Novice C programmer having trouble with strings & malloc

I'm starting off in C programming, and I'm currently studying structures and using pointers to work with them. I've been trying to write a simple program which stores your personal details (name and birthday) for practice, but I've been having…
dkd6
  • 65
  • 1
  • 6
0
votes
1 answer

Making a working copy of char array of unkown length

Using MPLABX 5.35 with XC16 v1.36 for a PIC24FJ128GB204. Limited c background, but learning. I'm trying to write a function that takes a (pointer to a) string in a char array (of unknown size) and edits it in-place to right-justify it and pad it…
0
votes
1 answer

What does strcpy (p, p+1) do (being p an array of chars)?

Eventhough I know what strcpy does I was unable to understand what it did in this specific case. Where I saw this it said that it copied the string p one character back, but I didn't fully understand why the source was p+1. The code where I saw it…
0
votes
1 answer

C-Segmentation Fault: 11

I got segmentation fault: 11 in my code, and i could not figure it out why. I got it after the second fgets. #include #include #include typedef struct Worker { char* name,addr,days; } Worker; int…
Benedek
  • 41
  • 4
0
votes
2 answers

Why does strcpy change the value of this one parameter?

Hi this code I created capitalizes lower case letters. strcpy manages to copy the value of string to stringTwo, however I was wondering why strcpy changes the value of string as well if I just used it as a parameter. Thanks #include…
jason96
  • 57
  • 5
0
votes
1 answer

Emdedded C strcpy copies only first 10 bytes

I am experiencing a problem in Atmel Studio when using memcpy or strcpy. When the switch evaluates to TYPE3, only the first 10 bytes are copied. When the order of the cases are exchanged with each other, other strcpy's work. I really cannot see why…
0
votes
1 answer

Seg Fault when allocating memory and setting values to 3D array

I want to create an array of 26 word arrays (to sort my lists of words by first letter) so I believe I allocated memory accordingly but when I try a test run and attempt to set a random word, "hi", to each spot which must have a word, it only works…
0
votes
1 answer

the strcpy function keeps crashing

#include using namespace std; defining class class fancyString { private: char *content; bool flag_bold; bool flag_italics; public: fancyString(){ content=""; flag_bold= false; flag_italics=false; …