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

Transfer char arrays into linked list

I have been hesitant to post a question about this because I'm worried about asking a stupid question, but here it goes: I am currently trying to create a program that will take whole strings, put them into char arrays and transfer those char arrays…
Starlncr34
  • 31
  • 1
  • 6
1
vote
3 answers

strcpy assertion error c++

I am a student Just learning c++ so I am sure there are much more efficient ways of doing this; with that said I would really appreciate some help figuring out why my program crashes. I have narrowed it down the a strcpy function that crashes…
1
vote
1 answer

A more elegant way to concatenate C strings in C++?

I was wondering if there was a less....listy way to do this? I have an assignment that puts credit card information in a UDP packet, with the information separated in the buffer by colons, so that it looks like Bob Jones:7845 6133 7889…
qwerty26
  • 61
  • 2
  • 7
1
vote
3 answers

C - Can't save string from inside for loop

I need to save the contents of tmp to tmp2. However tmp is always NULL outside of the while loop. if(1){ char* tmp; char* tmp2; // split the string on the space character tmp = strtok(actual_args[0], " "); …
user2121620
  • 678
  • 12
  • 28
1
vote
3 answers

Storing char pointers then fill it later on

I'm having a small issue here, so I'm storing a char pointer ( rather an array ), in a void pointer as following: char result[255]; CEVariable result_var(CEType::string, result); Now the result_var is then passed on to my engine, stored as a…
1
vote
5 answers

Program crash with pointers trying to make strcpy-like

This is my second problem today, pointers are giving me nightmares . I'm trying to make a program that do the same thing that strcpy() function do.. Once i try it..it crashes and i'm 100% sure that's a pointers issue in my code. I think because…
rafael
  • 709
  • 4
  • 11
  • 21
1
vote
2 answers

How to robustly copy text to char* without any errors

I have 2 questions.. is it necessary to add a termination character when executing the following commands against a char *string ? strcpy(); strncpy(); Is it necessary to allocate memory before before doing any operation with the above to function…
Muneer
  • 7,384
  • 7
  • 38
  • 62
1
vote
2 answers

strcpy seems to be messing with previous serial out on Arduino

I've always had a problem with the concept of char pointers, strings, Strings and most things pointer related. Maybe I'm too old for this ;-) declared globally: char * message; the serialOut is a very short 8 character string, an identifier (X10D)…
Madivad
  • 2,999
  • 7
  • 33
  • 60
1
vote
1 answer

How to mitigate the strcat and strcmp vulnerability?

I know that the whole family of strcpy, strcat and strcmp have buffer overflow vulnerability, to mitigate the strcpy vulnerability someone can use the strlcpy, what about the strcat and strcmp, are there safe versions of that functions or someone…
Avraam Mavridis
  • 8,698
  • 19
  • 79
  • 133
1
vote
2 answers

Trying to print out a matching char variable to cout

So I'm trying to make a coca cola machine to print out what the user has chosen to drink. Basically, I wan't to the user to input a word like "cocacola" as a string, then I convert that into a char type and use that with a if statement. But when I…
Bryan Fajardo
  • 161
  • 3
  • 15
1
vote
1 answer

The best way to implement the strcpy function

if I would call the strcpy function like this: char *s = NULL; strcpy(&s, "Test"); in the main function, would this be the best implementation of it: or there is a better way to implement the function? Thank you!
Zack
  • 385
  • 2
  • 3
  • 21
1
vote
1 answer

Assigning values from a static char array to a dynamically allocated char array

Today I was told that I would be able to easily take the contents of a static array and copy the data over to the dynamically allocated one. I searched for a long while and still have not found a good explanation as to how and why that is…
user3040968
1
vote
2 answers

How to copy a string into middle of character pointer

I have a dynamically allocated char array with pre_padding_buffer (size 8) and post_padding_buffer (size 6). I need to copy the string over to a character pointer like this: [ ][ ][ ][ ][ ][ ][ ][ ][e][x][a][m][p][l][e][ ][ ][ ][ ][ ][ ] The…
TtT23
  • 6,876
  • 34
  • 103
  • 174
1
vote
3 answers

My strcpy_s won't work with my char *pointer, why?

Ok, so I am trying to fix my C++ assignment, but when I use strcpy_s it only works for my array and not my *pointer.. here is what I am working with: HotelRoom::HotelRoom(char Num[], int cap, double daily, char* name, int Stat) { strcpy_s(room_Num,…
LoyalNewb
  • 43
  • 1
  • 1
  • 7
1
vote
2 answers

Segmentation fault when copying string to

Hit there! Below is a little program I made today. It takes a table of strings, reverses all strings without reversing table, then sorts those reversed string, then reverses them back, and at last prints whole table. I was trying really long to…
wnerw
  • 13
  • 3