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 in xcode

This is my code char strings[10][10] = {"aaa", "bbb", "ccc"}; strcpy(strings[0], strings[0]); I create a C project in Xcode, and then I run it which will be crash. But if it is a Objective-C project, it will be no problem
Zhi Chang
  • 35
  • 5
0
votes
1 answer

strcpy with size bigger than malloc

This was a question from an exam : does this code always works ? the answer is : the if statement checks if the virtual address of 'str' is pointed to the beginning of a page, only then the strcpy should be executed and it will work because the…
Rawhi
  • 6,155
  • 8
  • 36
  • 57
0
votes
0 answers

Call to strcpy() raises signal SIGABRT

I know it's a common question but I didn't find a suitable explanation yet! My project compiles but I keep getting the Thread: signal SIGABRT! - the strcpy function; nothing's written in the debugger window and when I debug step by step the test…
Raw305
  • 31
  • 5
0
votes
4 answers

strcpy works fine, even though memory is not allocated

Below c++ program works fine, even though i have not allocated any memory to chr. I went through google, SO and came across this Why does this intentionally incorrect use of strcpy not fail horribly? Here the program works fine for destination…
Rndp13
  • 1,094
  • 1
  • 21
  • 35
0
votes
2 answers

What does `strcpy(x+1, SEQX)` do?

I'm wondering what this syntax of strcpy() does in line 65 and 66: 24 #define SEQX "TTCATA" 25 #define SEQY "TGCTCGTA" 61 M = strlen(SEQX); 62 N = strlen(SEQY); 63 x = malloc(sizeof(char) * (M+2)); /* +2: leading blank, and trailing \0…
olala
  • 4,146
  • 9
  • 34
  • 44
0
votes
3 answers

Garbage with strcpy and strcat

I'm doing a client-server project in linux and I need to concatenate some strings. I tried my code on visual studio in windows and it works fine, but it linux it gives me some garbage. I've got this function: char* concat(char s1[], char s2[]) { …
luidgi27
  • 324
  • 2
  • 15
0
votes
2 answers

strcpy adding random numbers to empty string

I am trying to flush out a char buffer by using strcpy(buffer, ""). strcpy() seems to be putting random numbers in the string. In gdb, I see the buffers (received_message): Before strcpy() call: (gdb) print received_message $6 =…
Daniel Underwood
  • 2,191
  • 2
  • 22
  • 48
0
votes
2 answers

C - Use of strcpy in general

I have this snippet of code: new->name = zalloc(sizeof(char) * strlen(name) + 1); if (!new->name) goto alloc_failed; strcpy(new->name, name); Is the general use if strcpy() frowned upon even if space for name was pre-allocated. Just wondering…
Andrew Ricci
  • 475
  • 5
  • 21
0
votes
0 answers

malloc()ated string buffer gets corrupted in/right-before strcpy()?

So, I'm malloc()ating a variable, something like this in a function in C: char * foo; foo = (char *)malloc(32 * sizeof(char) +1); // some irrelevant (to the variable) code function2(&foo); free(foo); And then, I copy a string into foo in…
ShadoWalkeR
  • 123
  • 1
  • 8
0
votes
2 answers

adding a variable into a file path

I got the user id to add it to the file path. But am having trouble creating the file. How do I add the user id to the file path? I used strcpy but that does not seem to work. Here is my code. mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP |…
Aaron
  • 4,380
  • 19
  • 85
  • 141
0
votes
1 answer

Choosing a character from the array and subsequent replace the second array - C

I'm doing a function in C, which I of the field char letters[], which stores the features that I want in the char available[] delete / omit just that in the field were not. I found here stackoverflow replace function that I overwrite the string. The…
RapiDo
  • 3
  • 4
0
votes
3 answers

Char array in linked list causes core dump

I created a linked list program it works perfect with ints in c. but if change the parameter to char array, and try to do a strcpy it causes a core dump. #include #include #include struct node { char mac[25]; …
S.Regusci
  • 63
  • 6
0
votes
1 answer

C | pointers,arrays and segmentation issue

I have the following snippet #include #include #define SIZE 3 typedef struct node{ char *name; int id; } Rec; int main() { Rec n[SIZE], *p; int i; char *s[]= { "one", "two","three"}; for (i = 0; i <…
Aviad
  • 3,424
  • 3
  • 14
  • 21
0
votes
2 answers

I can't figure out strcpy

This is an unfinished code for converting alphanumeric characters into Morse code. So far only the character "A" is in set. I can't seem to copy the Morse code string of "a" into the variable "c". The compiler tells me that passing argument 1 of…
FrancisDoy
  • 81
  • 1
  • 6
0
votes
3 answers

Segmentation fault with System V shared memory

I am trying to understand why this simple code leads to a segmentation fault when I try to copy some characters into shared memory using strcpy: #include #include #include #include #include…
IbliSS
  • 25
  • 1
  • 7