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

I don't understand why I am getting "Segmentation fault (core dumped)" error

I am writing a C program which searches for a string inside a file. When I compile and execute the program from the command line, I get the segmentation fault error. I know that this error means that I do not have access to the memory I am trying to…
KOB
  • 4,084
  • 9
  • 44
  • 88
-1
votes
1 answer

When I malloc more space for a string within an array of strings, the array of strings duplicates some strings

I have an array of strings, and I am trying to malloc more space for one of those strings so I can change the value of the string. int catenate_strings (char** arr, int index1, int index2) { char *new_string; new_string =…
-1
votes
1 answer

How to copy the returned token by strtok

So basically I don't know how to work with this command well, I searched around the forums and could understand how to print the string and using the pointers but I want to divide the string and save all the tokens in different variables. I'm trying…
João Gomes
  • 81
  • 10
-1
votes
1 answer

strcpy_s throws exception "Buffer is too small"

int main() { const int SIZE = 4; char pin[SIZE] = { 1, 2, 3, 4 }; char temp[SIZE+1]; strcpy_s(temp, SIZE+1, pin); return 0; } This code throws "Buffer is too small" exception. However, it starts working if I make temp 14 or more: …
Vegeta
  • 334
  • 2
  • 4
  • 12
-1
votes
1 answer

Nested Structure,Error Reading Characters of String C

I've seen some other posts have the same question; However the other posts recommended using strcpy(). The problem is that I am using strcpy() and I am still getting this error. I would really appreciate it if someone could help me out on this one.…
Jordanthedud
  • 61
  • 1
  • 6
-1
votes
2 answers

Why is my strcpy() not overwriting the whole string and keeping characters from the last char []?

I have a simple method that takes in a file name and a pointer to a linked list. There doesn't seem to be anything wrong with the linkedlist. However, I noticed that for some reason, strcpy seems to be failing to overwrite the string that used to be…
Tyler
  • 49
  • 1
  • 11
-1
votes
2 answers

How do I append a formatted string into an array?

I have the following: char rank[100][100]; int score = 5; strcpy(rank[0], "%d" score); However, strcpy() does not accept these arguments. Is there any way to append a formatted string into my array?
yezi3
  • 1
  • 1
  • 3
-1
votes
1 answer

Bad access in Xcode

I wrote a code which produces the following error: Thread 1: EXC_BAD_ACCESS (code=1, adress=0x7.....) I want the program to link the countries, states, cities and shops within an structure. But when I try to run my program it gives me the error…
PeterPan
  • 684
  • 1
  • 10
  • 27
-1
votes
3 answers

Analysis on character pointer with dynamic memory allocation

I have written the following code in C. I need to understand how the string copy operations will be performed after the character pointer gets assigned memory via malloc() dynamically. My code: #include #include #include…
-1
votes
1 answer

strcopy crashing c program

My program takes name and age from command line arguments through name and stores each name and age as elements of a structure. My problem is strcpy crashing my program when I run it. Here is my code, I would appreciate any help that I can get. …
Flower
  • 381
  • 1
  • 6
  • 17
-1
votes
1 answer

strcpy runtime error / non-empty destination

could you tell me why strcpy produces a runtime error here? Should the destination string be empty? And if so, why? #include #include int main(int argc, char* argv[]) { char* input = "Nascartestdriver"; // strlen(input) ==…
ifox12
  • 9
  • 1
-1
votes
1 answer

Strcpy just crashes the second time I use in the same context

This code waits for a string entered by the user, then the program should sort it immediately in an pointer array. The problem is in the case cop<0. I don't know what's the problem with strcpy() . If anyone could help, I'll be thankful. Here is the…
-1
votes
1 answer

Segmentation fault in c strcat operation

What is the problem with this code sample? I get either I segmentation fault, or program continues to run infinitely. const char* prefix = "gender_"; char sex[8]; int id; for(id=0; id <= 9 id++) { …
nikk
  • 2,627
  • 5
  • 30
  • 51
-1
votes
1 answer

Printf and Strcpy Bug in C language

Here i wrote a piece of code. A function to add long numbers (used strings to represent numbers). I want to know about two bugs that I usually face while coding in C About printf statements , sometimes upon removing some printf statements i get…
Akash
  • 85
  • 1
  • 12
-1
votes
2 answers

strcpy Seg Fault

according to DDD I'm getting a seg fault from strcpy but I can't quite figure out what I'm doing wrong (still quite new to C). Any help would be greatly appreciated, thanks in advance. int compare_people(PERSON* first, PERSON* second) { char…
Sammdahamm
  • 11
  • 10