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

Valgrind: "Conditional jump or move depends on uninitialised value(s)"

I'm trying to write a function that adds a new struct into a linked list. Valgrind keeps giving me this error no matter what I do. Here is the code: /* Stores a new address record to the linked list * * Parameters: * first: pointer to the start…
Markus K.
  • 87
  • 2
  • 9
4
votes
1 answer

Intentionally Vulnerable Test Program Not Behaving as Expected

I have been playing around with intentionally vulnerable c programs using strcpy, sprint, gets, etc. These all behaved as expected when running on linux but something strange is happening on my OS X machine. Here is the program I have…
735Tesla
  • 3,162
  • 4
  • 34
  • 57
4
votes
1 answer

Function strcpy() changes value of integer array?

I'll start off with the code I have currently where input is a user provided variable: int current[2] = {-1, -1}, next[2] = {-1, -1}; char *strtok_result = strtok(input, " "); int i = 0; while(strtok_result != NULL){ i++; int count = 0; …
Anton
  • 1,435
  • 2
  • 10
  • 21
4
votes
2 answers

Replacing strcpy with strncpy

Let's say I have some legacy code which was written using unsafe calls to C STL functions like strcpy. We all know that strcpy is unsafe because it leaves a program vulnerable to buffer overflow issues. Let's say I want to replace all calls to…
RouteMapper
  • 2,484
  • 1
  • 26
  • 45
4
votes
4 answers

Comparing two strings, problems with strcmp

I'm trying to check if the line read from stdin begins with "login:" but strcmp does not seem to work. char s1[20], s2[20]; fgets(s1, 20, stdin); strncpy(s2,s1,6); strcmp(s2, "login:"); if( strcmp(s2, "login:") == 0) printf("s2 =…
Barsan Ionut
  • 45
  • 1
  • 1
  • 6
4
votes
2 answers

Program errors due to strcmp and strcpy in C

No matter how I edit my program there seems to be overflow errors and mismatching type errors. Can someone help me to make this run without errors. #include #include #include int main() { int choice; int i; …
4
votes
2 answers

Difference between array and pointer

Yesterday I had a little trouble with a homemade "strcpy" function. It works now though but I'm a little confused! char* a = "Hello, World!"; //Works char b[] = "Hello, World!"; //Works also strcpy(a, "Hello!"); //Segmentation fault strcpy(b,…
4
votes
2 answers

strcpy c++ cannot convert parameter 1 from string char*

i am trying to put the words that there are in a txt file* into an array of strings. But there is an error with the strcpy(). it sais: 'strcpy' : cannot convert parameter 1 from 'std::string' to 'char *' . Why is that? Isn't it possible to create an…
captain monk
  • 719
  • 4
  • 11
  • 34
4
votes
1 answer

Using strcpy with std::vector

I have some trouble using strcpy with a vector of instances of my own class. Here's the class: class elemente { char name[5]; short val; bool red; }; So, I made a vector from this class: vector ele(1); But if I…
StefanEuSunt
  • 133
  • 1
  • 6
4
votes
2 answers

does libc function "strcpy()" invoke any syscall?

I want to know if there is any libc function that does not invoke any syscall()? For example, for the libc function "strcpy()", does it any syscall (let's consider all possible linux systems).
Richard
  • 14,642
  • 18
  • 56
  • 77
4
votes
1 answer

strcpy causing EXC_BAD_ACCESS?

I am making a command-line tool using Xcode 4. I get the EXC_BAD_ACCESS error on the line with strcpy: char *invalidOption = NULL; strcpy(invalidOption, argv[2]); argv[1] is -v (a "valid" option) and argv[2] is -z (an "invalid" option). I then need…
Macro206
  • 2,143
  • 3
  • 19
  • 25
4
votes
4 answers

How to copy or concatenate two char*

How do you concatenate or copy char* together? char* totalLine; const char* line1 = "hello"; const char* line2 = "world"; strcpy(totalLine,line1); strcat(totalLine,line2); This code produces an error! segmentation fault I would guess that i…
mister
  • 3,303
  • 10
  • 31
  • 48
4
votes
6 answers

What is the difference between pointer and array in the following context?

#include int main() { char *pName = new char[10]; char dummy[] = "dummy"; strcpy(pName + 0,dummy);//how this is different from -->this works strcpy(pName[0],dummy);//this one...--> error C2664: 'strcpy' : …
yesraaj
  • 46,370
  • 69
  • 194
  • 251
3
votes
5 answers

Why no segmentation fault on strcpy?

Possible Duplicate: Undefined, unspecified and implementation-defined behavior This should seg fault. Why doesn't it. #include #include char str1[] = "Sample string. Sample string. Sample string. Sample string.…
siemanko
  • 1,389
  • 1
  • 13
  • 26
3
votes
5 answers

C++ std::string alternative to strcpy?

I know there is a similarly titled question already on SO but I want to know my options for this specific case. MSVC compiler gives a warning about strcpy: 1>c:\something\mycontrol.cpp(65): warning C4996: 'strcpy': This function or variable may be…
User
  • 62,498
  • 72
  • 186
  • 247