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

c++ c-strings, strncat, strncpy

This program is supposed to input someones name and output it like " Last, first middle". The names are supposed to be stored in 3 different arrays and their is a fourth array for the full name at the end. I am also supposed to use strncpy and…
user1807815
  • 83
  • 2
  • 12
0
votes
2 answers

how to write data within malloc memory in C

Suppose I have void * space= malloc(500) //alloc a block of memory and I need to write two strings and an int: "Hello world", "Goodbye friend",5 in memory address 50,150,380, correspondance to space.I tried the approach: int * insert = (int…
user2304942
  • 41
  • 2
  • 6
0
votes
1 answer

Why does VS throw an error when compiling an uninitialized string used in a strcpy function?

I was curious to know why the following code snippet works in some C compilers and not others. My professor can compile this code in DevC++ and so can I, but I can not compile this code in VS 2010. Any ideas? VS says a.word has a bad pointer. I…
John R
  • 350
  • 2
  • 5
  • 19
0
votes
4 answers

Not copying char arrays, function swap doesnt compile correctly and stringPtr is not modified

//In header file: class definition: class myString { public: myString(void); myString(const char *str); myString(const myString &); //copy constructor ~myString(void); //destructor void swap(myString…
Sam
  • 1
0
votes
1 answer

Issue writing to an array of strings

Having had issues with a slightly more complicated section of code, I've stripped away at it, but still the error remains. Could you cast a cursory eye over this and point out my errors? //before this, nbnoeud is defined and graphe is a stream that…
freewilly
  • 3
  • 1
0
votes
2 answers

strcpy() segmentation fault in 2-dimensional char** array

I'm currently programming a shell which grabs input and stores it in a string (char*) array. To enable UNIX operations like pipelining, I want to be able to write commands like echo this | function more | function2 To do this, I'm collecting the…
Shikai
  • 1
  • 2
0
votes
4 answers

What should we use as the second argument of std::strcpy?

I have the following example, taken from here: // strings and c-strings #include #include #include int main () { std::string str ("Please split this sentence into tokens"); char * cstr = new char…
Roman
  • 124,451
  • 167
  • 349
  • 456
0
votes
4 answers

C++: Appending to a vector string

I'm writing a "pig latin" program; read input from the users (first name and last name,) make the input lowercase and change the name depending upon what was in the name. If the first letter (of both the first and last name) was a vowel, we're…
Shea Hunter Belsky
  • 2,815
  • 3
  • 22
  • 31
0
votes
2 answers

read from binary file and copy into array

its time over but anyway i want finish this problem. I want read binary file to buffer and later i want copy this buffer to array. I'm doing like that; int i=0; char *buffer; buffer=(char *)malloc(filelen+1); //filelen is length of binary…
ccc
  • 93
  • 1
  • 3
  • 10
0
votes
1 answer

strcpy corrupts char array (string value)

The function below tries to order strings on a linked list in ascending order. When it returns the new list, it becomes corrupted. void* order( void *ptr){ struct wordlist *head; head = (struct wordlist *) ptr; struct wordlist *first =…
gzg
  • 1,469
  • 6
  • 23
  • 39
0
votes
3 answers

Segmentation Fault - strcpy() - C

I'm implementing a history feature for a command line shell. I've implemented a circular array to hold to ten most recent commands. Each command is also labeled by an integer specifying which total command is. For Example, if 30 total commands were…
Matt Koz
  • 67
  • 3
  • 10
0
votes
1 answer

2d array of strings and Strcpy fault?

I'm having a problem with assigning values to a 2d array of strings. Here's what the code: Char array[]= "Nary had a little lamb"; int chunkSize = 4; char inventory[totalRuns][chunkSize]; subString(result, array,0,0+chunkSize); …
p0ny
  • 329
  • 1
  • 3
  • 11
0
votes
2 answers

using strcpy for copying string into the element at index retrieved with atoi

Here's the code, which is supposed to execute the first command in history when "history 1" is entered: #include #include #include int main (int argc, char *argv[]) { int i=0; int j=0; int k=0; char…
serge
  • 366
  • 1
  • 4
  • 22
0
votes
3 answers

What's wrong with this strcpy with pointers function?

I've been tearing apart my program for hours trying to find the program. I've finally limited it to just a couple lines of code, but still I'm still stupid (or tired) to find the issue. All it is is a string copy function using pointers. Can someone…
Bobazonski
  • 1,515
  • 5
  • 26
  • 43
0
votes
3 answers

Need explanation of Word2 variable

I DO UNDERSTAND THAT THIS PROGRAM IS NOT ALLOCATING ENOUGH MEMORY. What I need help with is describing an explanation of what happens when this code is executed. I put "Since only 4 spaces are allocated it is not given enough space so it causes an…
ShadyBears
  • 3,955
  • 13
  • 44
  • 66