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
vote
3 answers

Error 0Xc0000005 in a program that tokenizes a list of numbers using strtok

I am currently programming a c program which gets text files as input. in every line I am getting a known ahead n float numbers, separated with comma. example…
1
vote
1 answer

Visual Studio 2013 strcpy_s and size of a word

I am new to C++ and I have started to work with strings recently, but I have problems with strcpy_s(). In Visual Studio if I use the old strcpy() it said that it is unsafe and after reading more on the internet and I found out why so I started to…
Bogdan Lica
  • 23
  • 1
  • 6
1
vote
1 answer

Are these strings concatenated correctly for fopen()?

I want to concatenate the two strings config_path and config_file and pass that string into fopen(). The problem is that fopen() returns an error even though I am 100% the file exists. As a matter of fact, I print the string in the command line…
loukouk
  • 69
  • 4
1
vote
1 answer

Segmentation fault (core dumped) error by strcpy() in C

I am trying to write a program that could read/write the rolodex info (the file will be named myRolodex by default). But I think the line: strcpy(filename,"myRolodex"); causes Segmentation fault (core dumped) in my GCC compiler. Any help to fix…
1
vote
4 answers

Copying float values into char array

I'm writing a TCP socket in C to send location data for a project I'm working on. So far, everything works, but I'm struggling with this seemingly simply problem. I'm trying to build a JSON String that will be sent over the socket. I have a…
James Taylor
  • 6,158
  • 8
  • 48
  • 74
1
vote
5 answers

is this code correct?If yes then malloc is already assigning the addresses to name[i] variable then why strcpy is used?

Following is the piece of code char str[20]; char *name[5]; for(i=0;i<5;i++){ printf("Enter a string"); gets(str); name[i]=(char *)malloc(strlen(str)); strcpy(name[i],str); } When in line 5 address of each string(denoted…
1
vote
3 answers

C: Using strcpy to transfer one struct element to an array

Okay, so we're supposed to prompt a user to enter 25000 lines of text. Each line contains three integers each. We are then to pass the third integer in that line to another struct, and connect each integer until you have 25000 interconnected…
Kyle Sanchez
  • 161
  • 1
  • 2
  • 9
1
vote
2 answers

Buffer Overflow strcpy()

I would like to know how many bytes do we have to overflow to run a shellcode ? int fun (char data[256]){ int i; char *tmp; strcpy(tmp,data); } It is known that: If string chain *data is larger than *tmp then there will be overflow. Otherwise…
BlaST77
  • 13
  • 1
  • 6
1
vote
3 answers

strcpy() is not copying properly c++

Recently I made a program, it has a character array board[8][8][2]; It is basically meant to be a 8X8 board which can store '2' lettered strings. I am not providing the complete code. But here is the problem. for (j = 0; j < 8; j++) { …
1
vote
2 answers

strcat to concatenate a and b without actually changing a or b

I know I can have a statement as such strcat( a, b ); int alen = strlen( a ); printf("a and b concatenated = %s and its length is %d\n", a, alen ); However, I want to preserve a, so I am trying use something more like this: strcat(…
tinkerton101
  • 25
  • 1
  • 8
1
vote
2 answers

Why is strcpy appending junk characters to the end of a small fraction of strings?

I have a function that takes as its input a string containing a hyperlink and is attempting to output that same hyperlink except that if it contains a question mark, that character and any characters that follow it are purged. First, I open a text…
cancub
  • 23
  • 2
  • 5
1
vote
0 answers

Using _strlwr from inside strcpy causes access voilation

A simple call to _strlwr from inside strcpy call causes access violation. Here is a example: int _tmain(int argc, _TCHAR* argv[]) { char dest[100]; strcpy(dest, _strlwr("TEST_STRING")); // Violation return 0; } However no Violation if string is…
1
vote
3 answers

Trouble with fgets() and strcpy()

I'm writing a C program which begins by opening and reading a file of 50 movie titles, each written on a single line. Next I am attempting to assign each line (or movie title) of the file into each element of an array called FilmArray[51]. I am…
KOB
  • 4,084
  • 9
  • 44
  • 88
1
vote
5 answers

C char pointer, char pointer copying char pointer. Whether it can be considered as a automatic / dynamic space creation in memory?

I write my own version of strcpy(). I learn it from http://pweb.netcom.com/~tjensen/ptr/ch3x.htm . So.. here is the source code: #include char *my_strcpy(char *dst, char *src); char *my_strcpy(char *dst, char *src) { char *ptr = dst; …
1
vote
2 answers

Getting a segmentation fault when trying to use strcpy() to a 2D char array?

I'm trying to write a function that takes in two strings, concatenates them, and then writes them to a 2D array. I have been messing around with different things and looking at other posts to no avail. The seg fault seems to occur in the last strcpy…