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

What is this line of code achieving? What does the incrementation mean?

I understand that s and t are both pointers and they are being copied to one another but the incrementing part is confusing to me. void funct(char *s, char *t){ while( *s++ = *t++ ); }
-1
votes
1 answer

why does it show segmentation error in my code?

this is the code for printing the two strings together but whenever I try to run it, there's a segmentation error but it compiles without any error, can anyone help? #include #include #include typedef struct node { …
-1
votes
3 answers

Copy a string to a *struct member

I've looked through topics of similar kind, but didn't find a solution for my problem. I've got a struct like typedef struct { int number; char *string; } mystruct; //Then define a pointer to the struct: mystruct *data; // Allocate…
rebit
  • 51
  • 5
-1
votes
1 answer

Strcpy function in c

Output is:Hello Hello As you can see the image Can someone tell why I am getting this output! Destination is Capable of holding only one character then how it can print entire string.
-1
votes
1 answer

Passing destination string as a pointer in strcpy

I recently came to know about a function called strcpy , the syntax of strcpy is char*strcpy(char * destination,const char * source) , so destination string can be a pointer to char , but the output of my code is null , why ? #include…
Prince
  • 119
  • 1
  • 8
-1
votes
4 answers

How can a string appear longer than its declared length?

I have declared the same size of two char strings (str1 and str2). After that, I read a string through gets() function and store it on str1 then copy str1 to str2. when they are displayed, I realized str2 can store more characters than its…
John Tran
  • 11
  • 2
-1
votes
1 answer

Input 50 characters into a string in C

#include #include #include #define _CRT_SECURE_NO_WARNINGS int main(void){ //declare 3 char arrays to hold 3 strings of 20 characters each. char string1[51]; char string2[51]; char string3[51]; // Prompt the user…
MaciG13
  • 13
  • 4
-1
votes
1 answer

Split a string to an array of strings, along with a flag

I'm trying to write a code in c that return 1 if there is "&" in the string and 0 otherwise. In addition, the char* that I receive in the function I want to put it in an array of chars and NULL in the end. My code is like this: char**…
Pedro Gómez
  • 214
  • 1
  • 8
-1
votes
1 answer

Struggling with strcpy and hash tables

I've an assigment about hashes. And i've finished my work. At least i thought so... Anyway My duty is creating a structure and indexing it with a hash table. I've done all the functions etc. but when i want to take some imput to my struct exe file…
Kaan Deniz
  • 23
  • 1
  • 5
-1
votes
1 answer

converting specific part of string to integer

*updated with how i stored the string into my struct I have a struct as below: struct patient { char name[30], ID[8]; int age, phoneNo; }; and i've written the following code: int searchName() { char search[30]; char record[60]; …
cloud
  • 105
  • 9
-1
votes
2 answers

Understanding malloc with char pointers and strcpy

I want to write a simple program and I want it to fail to understand strcpy and proper memory management but it still executes. I am trying to dynamically allocate memory (with malloc) for a string enough for only 3 (or anything less than the…
Onederfoo
  • 77
  • 1
  • 1
  • 7
-1
votes
2 answers

Segmentation fault strcpy/strcat

I am writing a program to open a file (say "input_file"), manipulate its contents and then output it to another file ("manipulated-input_file") I have done this with strcpy and strcat in the following way: char t-filename[]="Manipulated-",…
JohnP
  • 109
  • 1
  • 10
-1
votes
2 answers

best method to assign new string value to char array

I know that I have to use strcpy / strncpy to assign a new string value to an existing char array. Recently I saw a lot of code like this char arr[128] = "\0"; sprintf(arr, "Hello World"); // only string constants no variable input //…
-1
votes
2 answers

Need help understanding this C program which simulates strcpy() with a function

This is my code. I am trying to simulate strcpy(). This code works, but I have a couple questions. #include #include char *strcpy(char *d, const char *s); int main() { char strOne[] = "Welcome to the world of…
supahsonic
  • 19
  • 1
-1
votes
2 answers

why won't %s print from a linked list

I created a linked list that contains a char array. Then I tried to print it using %s and it would not print. I know I have to transform the char by adding in '\0' so that it can print using '/0'. But I'm not sure why. For example if I input: Bob…
Katie Melosto
  • 1,047
  • 2
  • 14
  • 35