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

Problems with string arrays, strcpy and strings

I'm having real trouble working with strings and string arrays, and using strcpy correctly. I'm using a dictionary of words scanned in a 2D array dictionary. Then I take a start word, alter every letter of it to create many different variants, i.e…
Finlandia_C
  • 385
  • 6
  • 19
0
votes
1 answer

Transferring data between strings in C

I'm trying to get this code to work, however I can't see any problems with it. Scores are inputted for each of the 8 games, and then the winner's name is meant to be imported into a new name array. However, the logic only seems to work on certain…
Pete
  • 84
  • 10
0
votes
1 answer

nested if statement failing

I am trying to set up a function that looks at a string of text, and replaces "y" with "ies" to make it plural. The problem I am having here (aside from ignorance), is that the function will not enter the 1st nested if statement. ( char…
0
votes
1 answer

strcpy giving segmentation fault in c

Hi please help me with this #include #include #include int classmatesize=0; char **classmate1; char **classmate2; void checkclassmates(){ int i,j; for(i=0;i
0
votes
2 answers

way to copy a string in a structure having character element in c

I have structure typedef struct { char employee_name[32]; char organisation[32]; }info; How can I Initialized a single or more elements of info . I am doing like this at the start of the code: info info_data= { …
Raulp
  • 7,758
  • 20
  • 93
  • 155
0
votes
2 answers

Strcpy segfaults after Malloc

So, i was writing a a simple slice function in C, which takes an array of strings, the string that marks the beginning of the slice, and the size of the slice. in the function i malloc a new array, and then proceed to copy over each string in the…
0
votes
3 answers

I want to convert a string to a char using strcpy_s, but it gives a size error

I'm trying to use strcpy_s, but i get another error dealing with the size, saying : L "Buffer is too small && 0" when i try to run the program, and i dont know ifsizeof tochar from strcpy_s(tochar, sizeof tochar, test.c_str()); is correct because…
donnie
  • 17
  • 1
  • 7
0
votes
1 answer

strcpy() and string left shift gives wrong result

In some project i have piece of C code that works wrong, but only with particular input string. I compile this piece only: #include #include #include #define slength 1000 // max string length char ss[slength]; int…
user2223633
  • 151
  • 1
  • 1
  • 10
0
votes
1 answer

C strcat/strcpy to character pointer not printing correctly

I have a simple program where I'm trying to learn about strcat and strcpy. However, it doesn't seem to be working quite right. It seems to copy and append just fine. However, when I print I think it is accessing memory locations outside of its…
neby
  • 103
  • 1
  • 2
  • 9
0
votes
1 answer

How can I convert an string array into a char array?

I have read several lines from a text file using std::getline, but now I need to convert the string array of lines into a char array so that I can use isalpha and isdigit. The ultimate goal here is to identify which chars are numbers and which are…
Code4Fun
  • 41
  • 1
  • 5
0
votes
2 answers

Don't understand the behavior in the example - strcpy() and function returning address of local array

#include #include using namespace std; /* The functions defined below are attempting to return address of a local variable and if my understand is correct...the main function should be getting garbage. */ int *test1(){ …
0
votes
2 answers

how to find overlaps between src & dest in strcpy(and similar functions)

suppose I have many appearances of strcpy,strcat & memcpy in our project (a very big one!) . How can I easily detect all the places I have an overlap between source and destination pointers. I know that valgrind can do it but not all cases can be…
almog
  • 51
  • 9
0
votes
2 answers

How do I get strcpy destination string just big enough?

I've resumed C coding for fun after a several year absence. I've given myself an exercise to safely copy text from standard input to strings using fgets(), and copy to a string just big enough, i.e. only with enough capacity to hold the no. of chars…
0
votes
1 answer

does safe_strcpy in samba checks if the memory allocation was successful

I am trying to copy a string to another using safe_strcpy but can't seem to find the function definition. This is what am doing: char value[256]; char *var = NULL; var = malloc(sizeof(value)); safe_strcpy(var, value, strlen(value)+1); I wanna…
xerocool
  • 113
  • 2
  • 10
0
votes
2 answers

how to override functions from stdlib

I would like to override strcpy and to supply my own implementation, in my strcpy I want to do something and call to the original strcpy. How can I do that? I'm working on linux, compiling with gcc, so I read about built in functions provided by…
almog
  • 51
  • 9