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
1 answer

C Concat String Int Sprintf

why is the the second sprintf not working? char* jc; char* tn; char* result = malloc((256)*sizeof(char)); int thread=99; int jobcounter=88; sprintf(jc, "%d", jobcounter); sprintf(tn, "%d", thread); …
Vor Name
  • 221
  • 1
  • 8
-1
votes
2 answers

Unable to delete object that used strcpy()

Recently I was deleting an object and an exception would get thrown, and I have narrowed it down to the use of strcpy(). To test this, I made a simple test class that uses (basically) only strcpy() and voila, an exception. #pragma once class…
-1
votes
3 answers

Isn't strncpy better than strcpy?

I know there are a lot of answers on the web which say one is better than the other but I have come to this understanding of strncpy() is better in terms of preventing unnecessary crashes in the system because of the missing '\0'. As many people put…
haveri
  • 29
  • 1
  • 2
-1
votes
2 answers

Strcpy changing struct int array

I have a struct in C, and I create an array of this struct typedef struct { int aNum; char name[20]; char sym[10]; char class[30]; float weight; int shell[SHELLS]; } element_t; element_t elements[MAX_ELEMENTS]; I am asking…
Runner
  • 115
  • 2
  • 11
-1
votes
2 answers

Using strcpy in C++ while defining _CRT_SECURE

im starting to learn C++ (just finished with C) and Im trying to use strings. Ive included the library, and i get this error when compiling: Severity Code Description Project File Line Suppression State Error C4996 'strcpy':…
-1
votes
2 answers

split string in C different variables

I have a string like: char string = " dog beans 1234 cat rice 0123 bird peanut 7777" I would like split that in different variables like: char animals[1000], food[1000], numbers[1000]; What I did until now: int i; while (string != NULL) { for…
-1
votes
2 answers

Copying 1D string into 2D array element

I'm working on a program in which overwriting a part of a 2D array with a 1D string is a necessity for the algorithm. The part that is supposed to do the overwriting is as follows: char twoD[MAX][MAX]; int top=2; int main(){ char arr[MAX]; …
-1
votes
2 answers

Trying to overflow but not working as expected

I am trying to overflow one buffer in to another as a laboration to learn. char* tmp_test = malloc(8); char* tmp_test2 = malloc(8); strcpy(tmp_test2,"ABCDEFG\n"); strcpy(tmp_test,"abcdefghijklmnopqrstuvxyz\n" ); printf("1th string…
Jacob
  • 371
  • 3
  • 12
-1
votes
1 answer

string not printing correctly in for loop but printing okay before

I am working out of a textbook learning c. One of the exercises is literally copying the code from the book to demonstrate using scanf. It gets user input for how many times something should be printed. Using a for loop to print out the string, the…
rayzor
  • 40
  • 1
  • 7
-1
votes
1 answer

Assign value to struct in C

I'm building a game, and when I change the value in 2d-map using the following code char example[100]; strcpy(example, " "); strcat(example, player1->unitName[j]); strcat(example, " "); map->map[x][y] = example; the whole values I put with example…
Lebanner
  • 77
  • 1
  • 1
  • 9
-1
votes
2 answers

String copy is saying buffer is too small, strcpy_s source issue

I'm so confused, I'm sorry if this obvious, but: int main() { char stringDest[20]; char stringSource[20]; strcpy_s(stringDest, stringSource); return 0; } Throws the exception "Buffer is too small". Whereas: char…
Zebrafish
  • 11,682
  • 3
  • 43
  • 119
-1
votes
3 answers

Copy a single character from a character array to another character array in C

I am fairly new to C programming and trying to improve. I have seen a few question similar to this and tried to implement their suggestions using strncpy but it still won't work. Can anyone give me a pointer in the right direction? Thanks. The aim…
James
  • 223
  • 1
  • 3
  • 9
-1
votes
2 answers

How to substitute variables names in C

#include #include #include #include int main() { const char mot1[] = "POMME", mot2[] = "POIRE", mot4[] = "PASTEQUE", mot5[] = "MELON", mot6[] = "ORANGE", mot7[] = "FRAISE", mot8[] = "FRAMBOISE", mot9[] =…
Amin NAIRI
  • 2,292
  • 21
  • 20
-1
votes
2 answers

c++: strcpy not working with char array

I'm sorting an array of names and my IDE is giving me "no matching function for call to 'strcpy'. Here are the values I set up: char Names [MaxNames] [MaxCharsPerName + 1]; const int MaxNames (20); const int MaxCharsPerName (15); Here is…
Caleb Lawrence
  • 131
  • 1
  • 4
  • 11
-1
votes
2 answers

Segmentation fault: 11 while trying to parse string

I'm trying to parse an input string into a command string and an array of arguments strings. I'm having some issue using strtok and strcpy, I think that my command string is not being null terminated properly which is leading to the seg…
TheNotoriousWMB
  • 139
  • 2
  • 11