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

Concatenation string with const char(result GetComputerName) on C++

Need: Concatenate the result of the function GetComputerName (nameBuf) with the command to open the Chormium. Objective: Create a new profile with the name of the machine that is being carried out the installation. Problem: I do not know how I can…
Globsecure
  • 132
  • 2
  • 11
0
votes
1 answer

How can I read multiple data using strcpy

I have a project completed where I read in a file and assigns the data in the txt file to a matrix. The problem I am having is that I have 8 data files named data1.txt through data8.txt. I need to find a way to loop through the the data file names…
0
votes
1 answer

strcpy: Use a char** variable in union as an argument

Hello I am trying to copy a string into "word" variable. strcpy requires char* type, and my "word" variable is char** type. How do I make it happen? I tried following, but it does not work. struct command { enum command_type type; char *input; …
Peter Hwang
  • 971
  • 1
  • 12
  • 25
0
votes
1 answer

about 'strcpy' function using

char input[32]; char name[32]; char discountUser[32];//not sure to using about arrays. char notDiscountUser[32];//not sure to using about arrays. int i,j; int len; fgets(input,32,stdin); sscanf(input,"%s",name); len = strlen(name); for(i=0,j=0; i <…
Barbiyong
  • 147
  • 1
  • 4
  • 14
0
votes
5 answers

Why do I get a strcpy runtime error in my code?

I've been trying to make my code work on Windows (moved from the Mac) and for some reason I get a runtime error related to my strcpy call. Please help!! Cust.h /* * Cust.h * Project 3 * * Created by Anthony Glyadchenko on 11/17/09. * …
Anthony Glyadchenko
  • 3,572
  • 7
  • 48
  • 66
0
votes
5 answers

C copy char * to char[]

Hello I am trying to copy a char * pointer to a char [] array. this is my code so far char * string_add(char * base, char * toAdd) { char * string=malloc(strlen(base)+streln(toAdd)+1); sprintf(string,"%s%s",base,toAdd); char…
SevenOfNine
  • 630
  • 1
  • 6
  • 25
0
votes
1 answer

strcpy 2D Array problems in functions

May I ask what is wrong with my code? strcpy seems to be working only inside the function. But when I'm passing it to another function, the first array prints okay but the other ones don't print correctly? What seems to be the problem with my code…
roldChang
  • 3
  • 1
  • 2
0
votes
4 answers

Finding the error in my use of the strcat function

Please help me i can't solve this question i've got in university. I asked in our university forum and they said this clue: "what is the difference if you send a long string to strcat, or you send the string B? " Explain what is wrong with the next…
user2630165
  • 311
  • 3
  • 10
0
votes
2 answers

Segfault trying to strcpy a char *

I am in a introductory C++ course and my program is segfaulting in my copy function. when I use GDB it says it cant access the char * at location 0x0. the odd thing is that I have written this function many times before without any errors. class…
Gizmo
  • 1
  • 2
0
votes
6 answers

Replace char in string with another string in C

I'm trying to replace ' ' (space) with '___' (triple underscore) in C. Here is my code: #include #include #include int main() { char *a = "12 34 56"; int a_l = strlen(a); printf("str1: \"%s\" (%d)\n", a,…
tpimh
  • 446
  • 2
  • 9
  • 23
0
votes
2 answers

warning: passing argument 2 of ‘memcpy’ makes pointer from integer without a cast [enabled by default]

for the following snippet: /* get IP address on a specific network interface */ void get_ip_dev(char* ipaddr, char* interface) { int fd; struct ifreq ifr; fd = socket(AF_INET, SOCK_DGRAM, 0); …
misteryes
  • 2,167
  • 4
  • 32
  • 58
0
votes
4 answers

What's wrong with my strcpy?

I tried to make strcpy myself. It should work, I even copied and pasted the (almost exact code) from someones post here about strcpy. Both give me a "Segmentation Fault". char* strcpy(char * destination, const char * source) { while(…
0
votes
5 answers

strcpy() of a small string into a bigger string leaves the rest of the bigger string unchanged.How to deal with it?

Here in this sample program to illustrate this behavior of strcpy(),I wrote a string "S" into a bigger string previous which original had "Delaware".But this overwriting only affects the first two characters in the original string.The rest of the…
Rüppell's Vulture
  • 3,583
  • 7
  • 35
  • 49
0
votes
3 answers

expected identifier or '(' error when assigning variables to members of a struct array

Here is the header file im using: typedef struct room room; struct room { char name[21]; int num_doughnuts; int num_milkshakes; room* portal[4]; }; and my code: struct room* create_room() { for(i = 0; i < num_room; i++) { …
0
votes
2 answers

Dynamic Allocation from input file

Consider the following: typedef struct wordType { char word; uint count; }; int main( void ) { typedef struct wordType * WORD_RECORD; WORD_RECORD arrayOfWords = malloc(10 * sizeof( WORD_RECORD) ); FILE * inputFile; char…
Busch
  • 857
  • 10
  • 29