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
5 answers

Reverse words in C Language

I'm trying to reverse the letters for words in a sentence. I am also trying to store these words in a new char array. At the moment I getting a runtime error, which for all my tweaking I can not solve. My approach is to create a new char array the…
Calgar99
  • 1,670
  • 5
  • 26
  • 42
-1
votes
3 answers

Trouble with strcpy

I'm terrible with C, and am having trouble with strcpy. I'm trying to grab one of the function arguments and store it in a char array. When I run this, I get a segmentation fault, but I don't see why. What am I doing wrong? Thanks! struct bb_state…
AndroidDev
  • 20,466
  • 42
  • 148
  • 239
-1
votes
4 answers

recursive strcpy function

#include char *strcpy_r(char* s, char* t); int main() { char *s = {"Bob"}; char *t = {"Billy"}; char *ptr; ptr = strcpy_r(s, t); printf("%s\n", ptr); return 0; } char* strcpy_r(char* s, char* t) { if((*s = *t) != '\0') …
Bonnie
  • 461
  • 3
  • 11
  • 14
-2
votes
2 answers

How many bytes are copied when I use the strcpy function on a String of n characters?

for example, char pass[0x10]; char str1[0x10] = "hello"; strcpy(string1, str1) Does this copy 1 * 5 bytes, plus 1 more bytes of the \0 null terminator? So 6? Im pretty new to low level, so I'm struggling to understand the Bytes concept.
natitati
  • 35
  • 4
-2
votes
1 answer

expected 'char * restrict' but argument is of type 'char' ,char * __cdecl strcpy(char * __restrict__ _Dest,const char * __restrict__ _Source); in C

I am trying to copy the value of argv[i] (which is a string) into a char array x[10] by using strcpy(). Code: char x[10]; int main(int argc, char *argv[]) { for (int i = 1; i < argc; i++) { strcpy(x[i],argv[i]); …
heyharshal
  • 13
  • 3
-2
votes
1 answer

Data storage error in using strcpy_s with char array & other miscellaneous errors

I'm having a problem allocating the char array in my get_company_info() function and am having seg faults in the get_employees function. I've played with couts in the functions and can't figure out what I'm doing wrong, only junk prints int main()…
Eddy2022
  • 1
  • 1
-2
votes
1 answer

simple strcpy from string to string crashes entire programme

sorry if this is a commonly asked question but I'm not sure as to why this code will not output anything: #include #include int main() { char source[] = "hello world!"; char **destination; strcpy(destination[0],…
LBradley
  • 11
  • 1
-2
votes
1 answer

C++ how to use strcpy for a 2d array in a struct

My compiler gives me an error when I do this: strcpy(skin.conclusion[0], "Mel"); My struct looks like this: struct list{ char conclusion[10][4] = {}; }skin; What am I doing wrong or is there something else other than strcpy that I'm…
-2
votes
2 answers

What happened to my strings in both strcpy() and custom function?

I have been doing well with the string functions I've been making recently. So then, I made my 3rd string function that is basically like strcpy(): #include #include const char *copy_str(const char *str); int main() { char…
BMPL
  • 35
  • 16
-2
votes
2 answers

How to join characters?

#include #include int main(void) { char rez[100] = "\0"; char t = 97; char temp; strcpy(temp, t); strcat(rez, temp); printf("%s", rez); return 0; } I want to join the character 'a' to the result…
Fei Xu
  • 1
  • 1
-2
votes
1 answer

Seg fault when trying to convert strings inside an array, to a array of char*

I'm reading from a text file and taking in strings and placing them into two separate arrays. Ex: TargetArr[1] and TypoArr[1] are pairs. I need to be able to look at each letter in the strings so I've tried converting them into char arrays. I want…
R. Row
  • 19
  • 5
-2
votes
2 answers

converting strcpy_s to strcpy CPP

can someone please convert this line: strcpy_s(this->name, SIZE_NAME, d.getName()); to a strcpy function instead of strcpy_s? thank you
Adb
  • 21
  • 4
-2
votes
1 answer

C++ How to populate a static array of strings with new strings in different locations?

Say I got this char* MapIds[5000] = { "Northeast Asia","Hanyang","Pusan","Pyongyang","Shanghai","Beijing","Hong Kong", /*...5000 values etc../* }; I tried strcpy(MapIds[0],…
SSpoke
  • 5,656
  • 10
  • 72
  • 124
-2
votes
1 answer

SIGSEV on strcpy to a char pointer

Why do i get a crash on strcpy even. I tried appending a 0,\0,\n using sprintf and check in gdb that its appended correctly but still i get a crash. With malloc i dont get a crash, but somebody told me that malloc is not necessary in this…
anurag86
  • 1,635
  • 1
  • 16
  • 31
-2
votes
3 answers

C Reason why strncpy not have null termination

I'm currently learning strings in C, and a question arose: why doesn't the C developers make strncpy null terminated automatically? For example in the implementation of strncpy, why didn't people who make C language add this line: // dest denotes…
Falanke
  • 69
  • 5