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

"Abort trap: 6" error in C?

I'm a beginner to C but I have this code running on xcode through gcc on terminal: #include #include int main(){ char name[12] = "Roman Mirov"; printf("My name is %s\n", name); name[8] = 'k'; printf("My name…
Roman
  • 173
  • 2
  • 2
  • 12
5
votes
3 answers

Result of calling strcpy is different than expected

#include #include int main() { char src[]="123456"; strcpy(src, &src[1]); printf("Final copied string : %s\n", src); } When I use the Visual Studio 6 Compiler it gives me the expected answer "23456". How come this…
Blood-HaZaRd
  • 2,049
  • 2
  • 20
  • 43
5
votes
10 answers

Strcpy implementation in C

So, I have seen this strcpy implementation in C: void strcpy1(char dest[], const char source[]) { int i = 0; while (1) { dest[i] = source[i]; if (dest[i] == '\0') { break; } i++; …
Hommer Smith
  • 26,772
  • 56
  • 167
  • 296
5
votes
1 answer

jvmti agent fatal error on linux: C [libc.so.6+0x7ae68] strcpy+0x18

I have written a jvmti agent to trace method invocations. I code it with C and jvmti and jni functions. Our os is Fedora 15 and the agent is compiled into a .so file. When I test it with a non-trivial java program, it crashes and gives the following…
dzy
  • 81
  • 1
  • 4
4
votes
0 answers

strcpy valgrind invalid read of size

Possible Duplicate: The valgrind reports error when printing allocated strings I have code which simply copies string. I remember to allocate memory, but valgrind shows some errors and I don't understand this. #include #include…
patseb
  • 651
  • 1
  • 8
  • 20
4
votes
1 answer

strcpy vs direct assignment: Overflow issue

This is a practice question from my school, it's not a homework question: Given the following declaration, write a snippet of C code that might lead to strlen(arr) returning no less than 8. char arr[4]; My attempt to this question is:…
DigitalSoul
  • 139
  • 1
  • 8
4
votes
7 answers

strcpy string array

char copy, array[20] printf("enter ..."): scanf("%s", array); if (strlen(array) > 20 ) { strcpy(copy, array....); what would I need to do to make it only grab the first 20 character if the input is more then 20…
Thao Nguyen
  • 901
  • 7
  • 22
  • 42
4
votes
4 answers

Safe Use of strcpy

Plain old strcpy is prohibited in its use in our company's coding standard because of its potential for buffer overflows. I was looking the source for some 3rd Party Library that we link against in our code. The library source code has a use of…
9Breaker
  • 724
  • 6
  • 16
4
votes
4 answers

Can´t print a String from a structure in C

typedef struct listaDocente nodoDocente; struct listaDocente{ //teacherList char Rut[12]; //ID char Nombre[50]; //Name char Correo[70]; //Email char Cod_Curso[6]; //Grade_Code …
Calu
  • 69
  • 1
  • 1
  • 8
4
votes
2 answers

C error:format '%s' expects argument of type 'char *'but argument 2 has type 'char (*)[100]'

I'm working on an exercise in c the last few days and I'm having this warning (as the title suggests). I've tried a bunch of stuff but I don't really know how to exactly fix this. I'm not good at programming so there are mistakes. Below are the…
Karamanis
  • 73
  • 2
  • 6
4
votes
5 answers

Structures in C with "no member named..." error

I'm trying to create a struct which contains the country, state, city and the name of a local shop. Unfortunately, I get this error: No member named bavaria in struct country So it seems that the error occurs here:…
PeterPan
  • 684
  • 1
  • 10
  • 27
4
votes
1 answer

strcpy was not declared in this scope?

#include #include using namespace std; int main() { char Buffer[20] = {'\0'}; cout << "Enter a line of text: " << endl; string LineEntered; getline (cin, LineEntered); if ( LineEntered.length() < 20 ){ …
Dawry Jones
  • 55
  • 1
  • 1
  • 6
4
votes
5 answers

Why C11 standard doesn't drop unsafe strcat(),strcpy() functions?

C11 & C++14 standards have dropped gets() function that is inherently insecure & leads to security problems because it doesn't performs bounds checking results in buffer overflow. Then why C11 standard doesn't drop strcat() & strcpy() functions?…
Destructor
  • 14,123
  • 11
  • 61
  • 126
4
votes
2 answers

Copy array of strings into another array in C

I'm making a word search program in C which takes the user input and then chooses one of the global arrays of words and uses that to generate the word search. It works when I just use one of the global arrays but not with the choice, I want to copy…
Declan Fitzpatrick
  • 152
  • 2
  • 3
  • 12
4
votes
6 answers

How to add null terminator to char pointer, when using strcpy

I have a program that's attempting to use the strcpy() function. I know that when one uses a char array such as: char array[10] the null terminator can be set by: array[0] = '\0'; However, how would I go about setting the null terminator(s) when…
user20842454566
  • 115
  • 3
  • 3
  • 12