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
0
votes
0 answers

How could I copy data using my own function of copy

As requested here I'm writing this post: I'm trying to copy data from std::string* to *char* . I'm using C++ . My approach is to convert std:string* to *char* then copy data. But I have a wrong result. This a part of data to copy : My code is the…
xtensa1408
  • 584
  • 12
  • 32
0
votes
2 answers

strcpy issue with char arrays in structs in C

So I'm working on a program to take in assembly code in a text file and produce the corresponding machine code. However, I'm running into an issue when I'm trying trying to assign values to the members of the AssemblyLine struct. What happens is…
Rohan
  • 33
  • 2
  • 5
0
votes
3 answers

Memcpy causing a seg fault in strcpy? Valgrind output included

I've tried replicating this bug I'm having in a project, but all efforts have failed, with my replications compiling and testing perfectly. Basically, I keep getting a seg fault that traces back to a call to strcpy in one of my files. I've managed…
user3773076
0
votes
1 answer

runtime-error "access violation writing location " with strcpy function

i have this run time error "access violation writing location " with strcpy function Here part of my code: else if (strcmp(sentenceRecv, "405002") == 0){ /*winVersion[SIZE] = (char*)malloc(sizeof(tempString));*/ system("ver >> text.txt"); …
Nir
  • 155
  • 1
  • 2
  • 10
0
votes
4 answers

C strcat() gives wrong appended string

I am appending a string using single character, but I am not able to get it right. I am not sure where I am making mistake. Thank you for your help in advance. The original application of the method is in getting dynamic input from user. #include…
GoodSpeed
  • 37
  • 4
0
votes
3 answers

How do I concatenate two strings (one's a variable) while still being able to reuse one of the arguments (the variable)?

I know this question has been asked, but the answers I looked at didn't really apply to my case. At the end of my program, a bunch of files are opened for writing. I've limited the list to just two for simplicity. The variable dirPath is a command…
aweeeezy
  • 806
  • 1
  • 9
  • 22
0
votes
2 answers

Can someone review this exercise? I was right, but want to clarify a few things

1 void myfunc(char** param){ 2 ++param; } int main(){ 3 char* string = (char*)malloc(64); 4 strcpy(string, "hello_World"); 5 myfunc(&string); 6 myfunc(&string); 7 printf("%s\n", string); // ignore memory leak for sake of…
Evan
  • 19
  • 2
0
votes
2 answers

Dynamic C - char pointers, strcpy, strcat

Here is my code: nodebug void sendLogPacketS(char *func, char *msg) { char * log; memset(log, 0, strlen(func) + strlen(msg) + 1); strcpy(log, func); strcat(log, ": "); strcat(log, msg); sendUDPLogPacket(log,…
Mike278
  • 35
  • 1
  • 3
0
votes
4 answers

Copying a substring to the start of the string in C

I am trying to remove the whitespace at the start of a string, I have the index of the first non whitespace character, so I tried to do this: int firstNonWhitespace = ...; char *line = ...; char *realStart = line + firstNonWhiteSpace; strcpy(line,…
Jonathan.
  • 53,997
  • 54
  • 186
  • 290
0
votes
3 answers

Buffer Overflow when using strcpy function

I'm trying to use strcpy in order to put a string in an array of strings. This is my definiton of the arrays: char movies[10][150], movie[150]; int i = 0, j = 0; currentChar = getchar(); while(currentChar != EOF) { while(currentChar!='\n') …
0
votes
1 answer

Issue with small example that uses strcpy in Xcode

I'm trying to understand this code below but Xcode is giving me an error at the 2nd to last line saying "Thread 1: signal SIGABRT" char string1[4] = "abc"; char string2[4] = "def"; printf("%s \n%s\n", string1, string2); strcpy(string1, string1+1);…
Arrow
  • 691
  • 2
  • 7
  • 15
0
votes
2 answers

Strcat keeps overwriting my char array?

buffeV is the problem here. When I strcat it is overwritten instead of appended. char temper[12];char buffeV[12];char buffe[2]; if(version<10) { sprintf(temper,"/0%d",version); strcpy(buffeV, temper); } if(version>=10) { …
0
votes
2 answers

Strcpy function changing a unrelated shared memory data

I'm a student working on a simple C program that implements two shared memory segments. The thing is that when I use strcpy function with the pointer to the second memory segment called nptr2 changes the value of the firt memory segment with the…
MuGiK
  • 351
  • 4
  • 13
0
votes
2 answers

C strings: Random characters appearing in memory after using strcpy and strcat

I'm trying to remove the file extension from a file so I can rename the file with the substring "opt.s". I do this with following simple example program: char in[5] = "hel.s"; char test[40]; strncpy(test,in,strlen(in)-2); char result[50]; …
John
  • 317
  • 4
  • 19
0
votes
2 answers

strcpy segmentation fault

i have a list of quads and they have a label starting from 1. the backpatch is taking a list structure which points at some quads. i want backpatch to update those quads, putting z on the char * fourth and then emptying l so i can put other quads…