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

Combine two strings into one in C programming

I'm having difficulty combining two string in C Programming, I want to be able to take an input files name from the command-line parameters and add .out to the files name as the output files new name. e.g. Test1.txt -> Test1.txt.out The code below…
IamTrent
  • 355
  • 1
  • 2
  • 13
-1
votes
1 answer

Two functions working in isolation, but not together

I have two functions rmdup and rmvow, when I run these functions in isolation they work perfectly, but when they're together in a program they don't work at all? int rmdup ( char name[] ) { char nodup[20] = {''\0''}; int l = strlen(name); …
Elis Jones
  • 327
  • 2
  • 15
-1
votes
3 answers

Assign a default variable if one is not inserted by user in C

So I am working on a class assignment and I have the basic program down but I am trying to go above and beyond the assignment. I have load from a predefined .dat file but I want to also give the user the option to define their own .dat file so here…
-1
votes
4 answers

strcpy function: C

I am trying to implement void strcpyy(char *s, char *t){ while(*s++ = *t++){ } } which is an example from K&R. The implementation should be fairly easy but for some reason, that is not the case for me at the moment. So I have the…
user3754974
  • 279
  • 1
  • 6
  • 15
-1
votes
4 answers

strcpy vs memcpy for copying char * with known size

I don't care about the NULL terminator so I have two choices: strcpy(createTabStmt, "CREATE TABLE "); //shorter and more readable code Or memcpy(createTabStmt, "CREATE TABLE ", sizeof ("CREATE TABLE ") - 1); //faster? Is the memcpy version always…
cshu
  • 5,654
  • 28
  • 44
-1
votes
1 answer

Having trouble with ascending insertion sort with strings in C

I am having trouble sorting out a list of names in c. I have code for sorting the names, but when I go to print them out they still are in the same order as they were at the beginning so something isnt right. So the function that I need help with is…
user3699735
  • 21
  • 1
  • 6
-1
votes
2 answers

Questions about strcpy overflows

I am using a simple main like this #include int main(int argc, char **argv) { char buf[256]; strcpy(buf, argv[1]); } I understand that if compiled, this main will produce 'argc' with a value of one, and argv[1] would not…
skrillac
  • 11
  • 1
  • 3
-1
votes
3 answers

How does this basic reimplementation of strlen() find the length?

My professor showed us this sample implementation of a function to find the length of a string, saying that this is how you would do it without actually using the strlen() function: int length(char word) { int i; for (i = 0; word[i]!='\0';…
Bob Ross
  • 61
  • 7
-1
votes
1 answer

How to bubble sort string within an array of structures

typedef struct { char name[50]; int age; int sex; } Person ; void sortAge(Person x[],int n) { printf("Age sort: \n"); int i,j; for(i=0;i x[j].age) …
-1
votes
2 answers

C - strpy, char*** crashing

I'm writing code for an assignment where we have to create a hashtable. One of the functions is to get all the keys within the hash table and assign it into a char* ** (triple pointer) given by the parameters. The char* ** is presumed to be empty,…
ginginsha
  • 142
  • 1
  • 11
-1
votes
2 answers

String loses data half way through execution C

While making an airline reservation system everything works well when entering a new flight, apart from the arrival location which is not being saved. I have done printf tests to see where the variable is losing its stored data. I have placed…
Matthew Cassar
  • 223
  • 2
  • 5
  • 13
-1
votes
4 answers

How to initialize a char* without first defining it's size

Right off the bat, I'm required to use dynamically allocated character arrays for my assignment, so do NOT suggest I just use strings. I need to create a method that accepts a character array as an argument, and inserts that character into a char*…
Dan Minor
  • 85
  • 4
  • 10
-1
votes
2 answers

strcpy crash with char *[] (ARGV Structure)

I have a problem with the c function 'strcpy' that I have not been able to figure out. it involves copying to a char *[] like Argv (but not actually Argv). I can copy out of the structure but not in. But only if I initially declare the entire Argv…
-1
votes
7 answers

Segmentation fault with strcpy()

This works: int main() { char *t = "Hello"; t = "World"; printf("%s", t); } But this gives segmentation fault: int main() { char *t = "Hello"; strcpy(t, "World"); // the only difference printf("%s", t); } Why?
user2076561
  • 139
  • 1
  • 2
  • 7
-1
votes
2 answers

Why is strcpy(strerror(errno),"Hello") not copying "Hello",but {ptr=strerror(errno);strcpy(ptr,"Hello");} does?

Please explain what's going on in the following program. I checked out the addresses returned by strerror(errno) at the beginning and end of the program and it confirms that it returns the same address each time.Then once sure of this,in first case…
Rüppell's Vulture
  • 3,583
  • 7
  • 35
  • 49