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

strcpy char pointer abort

I have this code: char **arr; char* line=NULL; int i=0; size_t len=0; ssize_t read1; fp=fopen("list.txt","r"); if(fp==NULL) exit(EXIT_FAILURE); while((read1=getline(&line,&len,fp))!=-1) …
Emil Grigore
  • 929
  • 3
  • 13
  • 28
0
votes
2 answers

Invalid read of size 1 Strcpy

I keep getting a valgrind error of Invalid read of size 1 and i can't determine why. What is causing the error? ==24647== Invalid read of size 1 ==24647== at 0x40258EA: strcpy (mc_replace_strmem.c:437) ==24647== by 0x8048606: main…
user1819801
  • 3
  • 1
  • 2
0
votes
3 answers

Segmentation fault in string copying

I'm getting the segmentation fault error for the inner while loop. char **c; c=(char **)malloc(3*(N-1)*sizeof(char *)); for(int i=0;i<3*(N-1);) { char *temp; gets(temp); while(*temp!='$') { j=0; while(*temp!=' ') …
Amit Gupta
  • 277
  • 1
  • 2
  • 9
0
votes
2 answers

Deleting information within an application in C

Ive got a phonebook app that the user can enter in contact information, and it will show up in the phonebook. I have a delete function that allows the user to search via the last name and delete the contact from the phonebook. My issue is that when…
DatDudeJC
  • 43
  • 1
  • 2
  • 9
0
votes
2 answers

manipulating strings in C

I am trying to write a method that removes the first letter of a string and appends it to the end of the string with "ay" appended afterwards. I am using a linked list structure, and it works, but something is not 100% and I can't figure out why. It…
cHam
  • 2,624
  • 7
  • 26
  • 28
0
votes
1 answer

C Programming Copy Substring

Im trying to copy substrings from one char* to another, when I printf(%c) it shows the chars printing, but at end of add method, i use printf(%s) to print entire string and nothing is printing out. Any help is appreciated - also perhaps a better…
Kairan
  • 5,342
  • 27
  • 65
  • 104
0
votes
3 answers

String copy(strcpy)

I have the following code. #include #include int main() { char * l; *l = 'c'; *(l+1) = 'g'; *(l+2) = '\0'; char *second; strcpy(second, l); printf("string: %s\n", second); } When I run it is says: The output says…
user1684072
  • 169
  • 2
  • 7
0
votes
3 answers

C strcpy and char

I need to write a code that will to this: You enter names and first names and a grade. Only for the grade >= 10, you print the names and firstname of the student with a backward…
hlx
  • 182
  • 1
  • 4
  • 15
0
votes
2 answers

usage of strcpy in functions

#include #include #include #include struct person *create_node(char *, char *,int); void addnode(char *,char *,int,struct person *); struct person { char fname[20]; char sname[20]; int pno; struct…
starkk92
  • 5,754
  • 9
  • 43
  • 59
0
votes
4 answers

add in a char* some other data c code

I have this part in a code: char* data="My name is: "; I would like to add to this the argv[1] argument with represents a name. How to do this in c code? I've tried strcpy and strcat but i have segmentation fault when Ipcp do…
just ME
  • 1,817
  • 6
  • 32
  • 53
0
votes
2 answers

C++: Using Strcpy with Pointer Strings

Possible Duplicate: Access violation when using strcpy? I have came onto something that is bugging me char* p = "Hello"; strcpy (p,"bye"); This always gives me an error, So how can I use strcpy with pointer strings. (and please nobody tell me to…
Mohamed Ahmed Nabil
  • 3,949
  • 8
  • 36
  • 49
0
votes
0 answers

How to convert LPCTSTR to char *

No matter what i do i just can't get it to work. ALL i want to do is take a LPCTSTR and a char* and concatenate them into a char* myfunction(LPCTSTR pass, LPCTSTR fail, LPCTSTR done, char* table,char* db_file, int s_time){ char…
Chris Rice
  • 728
  • 2
  • 9
  • 32
0
votes
1 answer

Can't do a strcpy from 2D array to another 2D array

Both are in the operator= in the same class here is the definition of the function. void segment::operator=(const segment& w) { strcpy(this->phrase, w.getPhrase()); //this line creates a problem. error is below: segment.cpp: In member…
Ali
  • 9,997
  • 20
  • 70
  • 105
0
votes
5 answers

Segmentation Fault while trying to copy string in C function

I have a function in 'C' that is supposed to implement my own strcpy program. Here's what I wrote. However, I am not able to debug the cause of Segmentation Fault. #include #include char * mystrcpy(char *dest, char *src) { …
Code4Fun
  • 125
  • 3
  • 13
0
votes
3 answers

why will strcpy only copy a limited number of elements:

C++ newbie here. Writing a simple program. Everything works,except when I attempt to extract firstname and surname and print these individually, the number of letters printed in surname will always be the same size as the number in firstname. So if…
LegItJoe
  • 15
  • 2
  • 6