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
vote
1 answer

C - how to use strcpy for a 2 dimensional array?

I'm trying to build a 2 dimensional array by using str.cpy, but the program fails. The code receives 4 arrays add copies their content to their matching arrays. int InsertStudent(char *firstName, char* lastName, char* dynCourses, char…
CS student
  • 33
  • 1
  • 1
  • 4
1
vote
2 answers

C string functions error

I'm working on an assignment, but I'm having trouble with my code : int is_ascii_match(const char c1[], const char c2[], char res[MAX_STRING_SIZE]) { .... if (val_c1 == val_c2) { strcpy(res, strcat(strcat(c1, '&'),c2)); } else …
sagi
  • 40,026
  • 6
  • 59
  • 84
1
vote
1 answer

Copying array to array using pointer

Like a question below, i have to use the pointer concept to copy array from one to another in mystrcpy2 function, unlike mystrcpy function that does not use the pointer concept. Anyway, I typed my answer, " dest = src;" which seemed to be overly…
Nathan Lee
  • 75
  • 1
  • 3
  • 10
1
vote
1 answer

__strcpy_sse2_unaligned with -fno-builtin

I was debugging my program, then the last line happened, how can I fix it? I used the -fno-builtin to have a look at the strcpy() but it shows that the __strcpy_sse2_unaligned is getting called. root@19:~/booksrc# gcc -fno-builtin -g…
bensua
  • 13
  • 3
1
vote
2 answers

strcpy_s buffer L buffer is too small && 0

i have a problem. i tried to proceede the following steps: char * str; char * s="Hello"; int len = std::strlen(s); str=new char[len +10]; strcpy_s(str,sizeof(str) ,s); But the programm displays the error, which i write in…
Perilun
  • 53
  • 1
  • 2
  • 6
1
vote
2 answers

C program copy string without using strcpy() with enough memory

I am trying to have this output: Comparing results of concat and strcat ... strcmp("Plain old stringTroy", "Plain old stringTroy") says: 0 The strcmp returns 0 if the two string arguments are identical. If the result is 0, then the concat behaves…
Yvette
  • 83
  • 6
1
vote
3 answers

Clarification of working of strcpy() when char array has been initialized like this *Arr

I was trying strcpy like this: int main() { char *c="hello"; const char *d="mello"; strcpy(c,d); cout<
Gaurav
  • 201
  • 1
  • 11
1
vote
1 answer

Getting unexpected results for array of strings when using = operator

In the below code I am getting unexpected result. During first iteration s[0] is getting printed as the first element. But during the remaining iteration, 0 is getting printed. Is it wrong to use = operator instead of strcpy? I tried using strcpy…
user3762146
  • 205
  • 3
  • 13
1
vote
2 answers

C - Copying a char to another

I am a beginner in C language. I want to copy a char array to another, but I cannot. I got these errors: Line 10 - [Warning] passing argument 1 of 'insert' makes pointer from integer without a cast Line 4 - [Note] expected 'char *' but argument is…
bluesshead
  • 45
  • 7
1
vote
4 answers

Advantage of using strcpy function in C

void main() { char s[100]="hello"; char *t; t=(char*)malloc(100); strcpy(t,s); } Alternatively, we could assign s to t like this: t=s;. What is the disadvantage of using the alternative?
nafiz amin
  • 97
  • 2
  • 6
1
vote
1 answer

strcpy misalignment __strcpy_sse2_unaligned()

What should be the correct approach(es) to solve __strcpy_sse2_unaligned() problems? ie. strcpy(enc_buf, base64_encode(buf)); leads to __strcpy_sse2_unaligned() in gdb So what are the precautionary measures to prevent such things?
ninja.stop
  • 410
  • 1
  • 10
  • 24
1
vote
1 answer

using strcpy to copy a string to a member of a structure via the pointer operator

I'm trying to use strcpy to set values for a char array which is the member of a structure. I want to do this using the pointer operator if possible. struct my_struct{ char foo[15]; } *a_struct_Ptr; int main(){ strcpy(a_struct_Ptr -> foo,…
Matt Hall
  • 331
  • 1
  • 4
  • 13
1
vote
1 answer

about the function strcpy_s

I want to output the smallest letters of the first letter of three countries, this is the code: #include #include using namespace std; int main() { void smallest_string(char str[][30], int); int i; char…
John Young
  • 57
  • 1
  • 8
1
vote
2 answers

C programming problem unrelated variable being overwritten after STRCPY is used

The problem is the variable nodeType is being changed after STRCPY finishes running. nodeType is not a variable that is related to any of the other variables being used in the STRCPY call. It is in the same struct though. nodeType is a enum with the…
MykC
  • 188
  • 1
  • 3
  • 13
1
vote
1 answer

Vector char strange chars

Anyone know how to copy to strings? Cause I used the function strcpy but when I print the result it show strange characters. I want to concatenate 'name' + '@' + 'e-mail'. With scanf I have to put the character null '\0'? #include #include…