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
vote
3 answers

strcopy function using pointers not working

I need to make a function that receives two char pointers and copies the contents of one into the other, and then returns the beginning of the pointer. I have been messing with this for a couple hours now and have read 100 examples that are all…
Cory
  • 37
  • 3
1
vote
1 answer

Old contained is also available(at some indices) even after copying new string to the existing string

I have learned that the work of strcpy is to copy the content of one string into another. Till now I was thinking that when we use strcpy then the old content is totally deleted and the new contained is copied. Kindly see the following…
Singh
  • 229
  • 2
  • 3
  • 7
1
vote
1 answer

Exception errors when using strcpy

I'm working on a BST for class. There are 5 files in the class, 2 1/2 of which I cannot edit (as an exercise in OOP). I cannot edit data.h, driver.cpp, or the public members of bst.cpp. I'm getting some exception errors when trying to use strcpy in…
FutureShocked
  • 779
  • 1
  • 10
  • 26
1
vote
3 answers

expected const char * but argument is of type char

This error keeps popping up and I don't know how to solve it. Please help! the error pops up in this line: ---fscanf(ifp, "%s", archive.team[i].color);--- There is also a "passing argument 2 of strcmp makes pointer from integer without a…
DavidT
  • 21
  • 1
  • 1
  • 5
1
vote
1 answer

Copying the string of pointer to other pointer

Folks, I have basic and simple question on pointers. The below is code is giving a segmentation fault. int main() { char *str = "hello, world\n"; char *strc = "good morning\n"; strcpy(strc, str); printf("%s\n", strc); …
1
vote
3 answers

String not displaying properly after being stored in shared memory

I have a data structure that acts as a buffer. It's two structures that have a char *color within them. I am able to store and retrieve the correct color out of each producer process by themselves, but the consumer does not seem to see anything in…
nicholas.reichel
  • 2,260
  • 7
  • 20
  • 28
1
vote
1 answer

strcpy causing segfault while using strtok

I'm not too sure why this code causes segfault. I'm trying to find out how many words does a sentence contain. Can anyone help me resolve this? #include #include #include #define MAX 1000 int main(void){ char…
stackyyflow
  • 767
  • 3
  • 11
  • 30
1
vote
5 answers

How to join strcpy in C++

im confused, in my coding C++ please help me.. #include #include #include main() { char h1[80]; char h2[80]; char move[80]; clrscr(); cout<<"Character 1 = "; gets(h1); cout<<"Character 2…
Ridwan Syah
  • 83
  • 1
  • 2
  • 10
1
vote
1 answer

strcpy function with pointers to character array

In the code below the result is stack overflow. Though null character is there with both the strings, so the strcpy loop should terminate as the source string has null character. Why stack overflow occurs?? #include #include int…
Siya
  • 71
  • 1
  • 1
  • 8
1
vote
4 answers

is malloc + strcpy function as good as calloc?

I've been looking for an answer to my question but I couldn't find any. I've read several times the difference of malloc and calloc. If you have an issue with speed, you should use malloc since calloc allocates + initializes the buffer to 0. Now, in…
user3714598
  • 1,733
  • 5
  • 28
  • 45
1
vote
1 answer

Copy results of strtok to 2 strings in C

Ok, so I have the code char *token; char *delimiter = " "; token = strtok(command, delimiter); strcpy(command, token); token = strtok(NULL, delimiter); strcpy(arguments, token); and it gives me EXC_BAD_ACCESS when i run it, and yes, command…
Mark Szymanski
  • 56,590
  • 24
  • 70
  • 87
1
vote
1 answer

How to process a string in NSIS?

I have a string from the parameters that has a installation path using this code: ${GetParameters} $R0 ${if} $R0 != "" StrCpy $R1 $R0 "" 3 StrCpy $INSTDIR $R1 -1 ${endif} the $INSTDIR contains a path like this: C:\Program Files…
Matin Lotfaliee
  • 1,745
  • 2
  • 21
  • 43
1
vote
3 answers

Dynamically construct a char in C

I am trying to construct an array that has a series of character that I want to construct in the fly, the characters are like this \x01, \x02 and so on. For example, lets say we have: #define NUMCOLORS 3 char delim[NUMCOLORS]; And we want to have…
Alejandro Alcalde
  • 5,990
  • 6
  • 39
  • 79
1
vote
3 answers

using strcpy to store a string that has many variables

I'm not sure how to word it, so the title may be unclear. Here's the line in question strcpy (stringstore,"int1: %d\nint2: %d\nint3: %d\nint4: %d\nstring1: %s\nstring2: %s\n",int1,int2,int3,int4,string1,string2); This is inside a for loop so the…
user3865562
1
vote
1 answer

Segmentation fault when sorting an array of strings when using strcpy in c code

Im trying to sort an array of string.If i remove the line strcpy(a[j-1],a[j]); terminal doesn't crash. The array of strings is allocated this way in case that s the problem array=(char **)malloc(sizeof(char *)*N); for(i=0;i
MattSt
  • 1,024
  • 2
  • 16
  • 35