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 -Implementing strcpy() But Segfault

I have made a strcpy() function in C, and I am copying words from one array to other not just letters, but when I run it I am getting Segmentation fault what to do? #include void strcpy1(char *dest[], char source[]) { while ((*dest++…
ady
  • 37
  • 4
0
votes
1 answer

C++ memcpy/strcpy of char pointer to class member char pointer

i have a custom class, let's call it "Student" and a main method. I'm instanciating the class, and just want to output the content of the class. My programm crashes with a: Process finished with exit code 139 (interrupted by signal 11:…
Ulf Tietze
  • 57
  • 6
0
votes
0 answers

Why strcpy crashes?

Why does the call to strcpy crashes in the following code? Also why is it crashing in CodeBlocks, but not in VS? #define MAX 500 char* GetUserAnswer(char* detail) { char answer[MAX]; printf("Provide %s:", detail); scanf("%s", answer); …
Gabriela
  • 29
  • 5
0
votes
3 answers

problem with strcpy() when trying to copy a string to a string

Recently started to do some c programming again and are currently having issues with an assignment. The following function are supposed to initialize a string by allocating memory for it, it is also the first assignment that I'm required to use…
Marcs
  • 3
  • 1
0
votes
1 answer

gcc is too smart to generate __strcpy_chk

My code looks like struct MyData { int len; char data[1]; }; MyData *d1 = malloc(1024); strcpy(d1->data, a_string); I use it as variable-length buffer and guarantee the buffer not overflowing manually and carefully. But the program…
Pan Ruochen
  • 1,990
  • 6
  • 23
  • 34
0
votes
0 answers

How do i change string value with strcpy in c

#include #include int main() { char str1[100]; char str2[100]; printf("(1) input str1: "); scanf_s("%s", str1, sizeof(str1)); printf(" input str2: "); scanf_s("%s", str2, sizeof(str2)); …
0
votes
1 answer

how to copy string a string to another one in mips assemply language

I've been trying to copy a string to another but couldn't find a way to do it can anyone help with this? here is the question: Write a program which will copy a string S to T using procedure call. Assume the string is null terminated. here is the…
suliman
  • 43
  • 8
0
votes
1 answer

How to copy string without allocating memory - C

I just started in C and this is a beginner question. But is there any way to copy a string without allocating memory beforehand? I want to reproduce the strcopy function inbuilt in C with the same structure (char *strcpy(char *src, char *dest);). I…
toni
  • 133
  • 1
  • 13
0
votes
2 answers

What causes the difference between memcpy and strcpy in copying openssl BIGNUM

This problem bothered me for an hour when I was programming, but I still didn't know the error of the original method after solving it. void generate_r_vector(char (*r_vector)[17],char *random_r) { BIGNUM* vector[127]; char r_v[128][17]; …
mikami
  • 43
  • 4
0
votes
2 answers

Why delete char array cause crash after assign a value by operator=?

This is my code. I create a char array and assign a string literal to it by operator=. After which, I free it by delete.However, it cause segmentation. But it works fine with strcpy. Besides, Is char array always assigned by strcpy? I got to this…
Caiyi Zhou
  • 143
  • 1
  • 9
0
votes
1 answer

Regarding structs in C, how to copy the data from a struct to a string array

I have a program if finds servers on the network using mDNS. It is from a opensource stack. Currently, I am in need of guidance for the following use case. USECASE: Whenever I run the program to findServers, I plan to add an additional logic, which…
0
votes
2 answers

EXC_BAD_INSTRUCTION using "strcpy" within a function

When I use the whole code in the main function it works perfectly but now I want to use the function for some "Strings" which I initialize in a 2D-Array. The idea behind the function is to create a product of a struct globally initialized. The line…
0
votes
1 answer

Abort Trap: 6 Error On Mac OS Using strncpy and strcpy

Any suggestions on the work around / alternative appreciated. I am trying to overwrite nulls before returning to calling function. Print statements included. else if (DB_SPC.option == OSTMP3) { /* overwrite nulls …
0
votes
1 answer

Understanding strcpy with array and pointer

I have a little code that merge strcpy array and pointer. I don't understand why the code displays "Good exam". I see that after the call to strcpy, ptr contains "lexam". So, can you explain when the value of a[] changes? char a[50] = "Good…
Rony Cohen
  • 51
  • 1
  • 9
0
votes
2 answers

Problems in C with const char * and strcpy()

I don't understand why when I run strcpy (ss, ss2) with char * ss and char * ss2 it shows segmentation fault. strcpy () just asks for 2 args of type char *, so I don't understand the problem #include #include int main() { …