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

Looking for code to benchmark C lib string and memory functions

I'm looking for existing code I can use to benchmark C lib memory and string functions like memcpy, memset, strcpy, strcmp, etc. I've done a google search and there are several hits for people who have done such benchmarking but everybody seems to…
0
votes
2 answers

What don't I understand about using strcpy() in Visual Studio 2010?

#include sdi12CRC::sdi12CRC() { CRC = 0; responseToDCommandWithoutCRC = new char[MAX_D_COMMAND_RESPONSE_SIZE]; responseToDCommandWithCRC = new char[MAX_D_COMMAND_RESPONSE_SIZE]; asciiCRC = new char[ASCII_CRC_SIZE]; …
Mike Jablonski
  • 1,703
  • 6
  • 27
  • 41
0
votes
2 answers

c: implementation of a rownames function

I have a 2d array of pointers (to strings) char *result[7000][14]; I want to write a function that returns the first string in each "row". Here's what I tried: char *getRownames (int a, int b, char *matrix[a][b]) { char *rownames[a]; …
JoshDG
  • 3,871
  • 10
  • 51
  • 85
0
votes
3 answers

Can't include iostream in C using MS Visual C++?

I've been trying to learn C, and I'm stuck on including libraries. I need to use strcpy(), but that method is included in the iostream library, but whenever I try to include the library, the program gives me errors. I've tried using "iostream",…
ZimZim
  • 3,291
  • 10
  • 49
  • 67
-1
votes
3 answers

C - strcpy pointer

I want to ask about strcpy. I got problem here. Here is my code: char *string1 = "Sentence 1"; char *string2 = "A"; strcpy(string1, string2); I think there is no problem in my code there. The address of the first character in string1 and string2…
lucifer
  • 13
  • 1
  • 2
-1
votes
2 answers

How can I modify Strcpy and strcat to sprintf

I'm new to C++ and i have to make a recurrent modification over a big project. I have to take all strcpy and strcat methods and convert them into sprintf. I figured out that basically, the conversion would be : strcpy(out,in) to sprintf(out, "%s",…
Franko
  • 131
  • 1
  • 10
-1
votes
1 answer

Issue with allocating char pointer

#pragma once #define _CRT_SECURE_NO_WARNINGS typedef struct Item { char* msg; } Item; typedef struct TreeNode* link; //typedef struct BSTNode* link; struct TreeNode { Item msg; // the data link pLeft; // left subtree link pRight;…
-1
votes
3 answers

Adding/appending string into an array of strings

Let's say I have an array that looks like: char arr[MAX_ARR_LENGTH][30] = {"Tom", "and", "Jerry" }; Now, how do I append a new string that the end of the array? Let's say I want to add "Jack" as a new element so the array shoud look like: char…
GoodBoyNeon
  • 103
  • 7
-1
votes
1 answer

Confusing strcpy() behaviour, concatenating to other strings

So Im loading comma seperated text from a file. 9780136019701,An Introduction to Organic Chemistry,Timberlake Karen,10,3.54,12-2008 9781506304212,Mathematics for Social Scientists,Kropko Jonathan,7,4.73,12-2015 9781506304213,Discrete…
Saif eldeen Adel
  • 318
  • 3
  • 15
-1
votes
2 answers

Assign a char* null pointer to an array of characters

I'm trying to assign a (char*)0 pointer to a string in C, but it doesn't work... Here is my code: ` char* token = strtok(command, " "); int counter = 0; while (token) { if(counter == 0){ …
-1
votes
1 answer

C code crashes when running strcpy() for the second time

I have a struct that looks like the following: typedef struct { char matrikelnr[10]; double note; } Hashtable_Entry_t; And then I try to fill the struct in the main: #include #include int main(int argc, char const…
J.Fasterling
  • 31
  • 1
  • 7
-1
votes
1 answer

I made my own strcpy function, but it is not working. How to fix it?

I attempted to make my own mystrcpy() function, which takes the same arguments as the standard function. It is not responding. The array does not get copied. size_t Mystrlen(const char* s) { int i = 0; while (s[i] != '\0') { …
malscode
  • 31
  • 5
-1
votes
2 answers

Having some confusion with pointers

I have the following code that I'm trying to decipher from a former colleague: void getIP(int p){ char tstr[80]; char *pt; strcpy(ipBuf,"NA"); if(p==-1)return; strcpy(tstr, panes[p].stream.c_str()); pt=strchr(tstr,':'); …
Cm1602
  • 91
  • 11
-1
votes
1 answer

strcpy function with dynamic allocated char array

I am facing problems to make this piece of code work: char **createCharArray() { char **charArray = new char*[PARAM_COUNT]; for (int i = 0; i < PARAM_COUNT; ++i) { charArray[i] = new char[MAXSIZE]; } return charArray; } …
Nik
  • 37
  • 6
-1
votes
1 answer

strcpy segfault copying file content to array

This is my code char url[MAX_WORD + 1]; char *urls[MAX_WORD + 1]; //char word[MAX_WORD + 1]; while(fscanf(fp, "%100s", url) == 1) { strcpy(urls[index], url); index++; } This is the error I'm getting on valgrind: ==43177== Process…