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
2
votes
3 answers

String vs String Literal: Direct assignment or strcpy/strncpy?

I think I have some issue understanding string and string literal. This is what I learned from my class, when passing to a function, const char * indicates this is a string literal, while char * indicates a string. Suppose I have a struct…
DigitalSoul
  • 139
  • 1
  • 8
2
votes
2 answers

Const char * vs const wchar_t* (concatenation)

which is the best way to concat? const char * s1= "\nInit() failed: "; const char * s2 = "\n"; char buf[100]; strcpy(buf, s1); strcat(buf, initError); strcat(buf, s2); wprintf(buf); It gives error. What should be the correct way? Thanks.
Azodious
  • 13,752
  • 1
  • 36
  • 71
2
votes
3 answers

Usage of pointers as parameters in the strcpy function. Trying to understand code from book

From my book: void strcpy (char *s, char *t) { int i=0; while ((s[i] = t[i]) != ’\0’) ++i; } I'm trying to understand this snippet of code from my textbook. They give no main function so I'm trying to wrap my head around how the parameters would be…
yiwll
  • 65
  • 4
2
votes
1 answer

Cannot catch access violation exception by use of C++ catch(...)

In the following code I want to catch either asynchronous and synchronous exceptions by use of c++ catch (...) according Microsoft Page descriptions about Exception Handling Model. Also I set the "Exception Handling Model" up to Yes with SEH…
2
votes
1 answer

Data Loss when trying to copy char* in C

I have been working on a project in C and I am having trouble when trying to copy char* using strcpy/memcpy/strncpy, none of these seem to work. The problem that is arising is that the words that are around 8 or more characters long are not being…
Brandon T
  • 25
  • 6
2
votes
3 answers

Size doesn't increase, yet it stores larger data. How is this possible?

I was trying this code in gcc6.3: char a[2]; char b[]="Aditya"; strcpy(a,b); printf("%s %lu\n",a,sizeof(a)); the output was: aditya@aditya-Gateway-series:~/luc$ ./a Aditya 2 How can variable a be still 2 bytes big and store an information of…
Aditya Gaddhyan
  • 354
  • 1
  • 14
2
votes
1 answer

../sysdeps/i386/i686/multiarch/strcpy.c: No such file or directory

I'm trying to debug a program with gdb and when I set a breakpoint and continue on the strcpy() function. I get the following response: frinto@kali:~/Documents/theclang/programs/helloworld$ gcc -fno-builtin -m32 -g -o char_array char_array.c…
user10199821
2
votes
7 answers

Why my source is changing when using strcpy in c

After using strcpy source is getting corrupted and getting correct destination. Following is my code please suggest me why my source is getting corrupted? If i keep a fixed size to second character array q[] then my source is not being changed. Why…
malathi
  • 21
  • 1
  • 2
2
votes
2 answers

strcat Function in c++

I'm new to C and C++ programming, can anyone give me a hint on what I'm doing wrong here. I'm trying to write to concat function that takes to pointers to chars and concatenates the second to the first. The code does do that, but the problem is that…
Milos.l
  • 41
  • 7
2
votes
2 answers

Convert string to character array, but strcpy() gives an error

Consider: void takeInput() { string word; cin >> word; int n = word.length(); // Declaring character array char *char_array = new char [n + 1]; // Copying the contents of the // string to char array …
2
votes
2 answers

How to modify a string inside a struct in C?

I am trying to modify a field inside a struct. I have no trouble doing this with other types (i.e. int, float etc.) but char * is giving me problems. I think I have to do something like: typedef struct{ char *string_field; }…
GCC
  • 21
  • 1
  • 2
2
votes
3 answers

C strcpy array of string pointers

I have an array declared like so: char *array[4]; which is populated by a different function with strings, i.e. ["one", "two", "three", "four"]. My goal is to copy this array into a new array, excluding the last two elements, so new_array would…
Paradox
  • 4,602
  • 12
  • 44
  • 88
2
votes
2 answers

Unsure how strcpy works in this situation

I am very new to C and working through a project as a way to help motivate me to learn. I was having a hard time getting the output from an sh popen. After much searching and hours of trial and i stumbled across a very old post where they…
2
votes
1 answer

c - strcpy not working with struct member and d_name

Whenever I try to use strcpy on a struct member (which is a static char array) and the d_name attribute of a dirent structure (used for reading a directory), my program doesn't get passed that point. I don't get any errors or warnings, it just…
Spencer Goff
  • 1,036
  • 3
  • 14
  • 23
2
votes
1 answer

MIPS Strcpy printing out garbage

So here's my code with the given argument; this is what my code ends up printing though. Test function _strCopy Please enter a string: test You just entered : test Result of _strCopy:…
ELlama
  • 33
  • 7