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
-4
votes
1 answer

Strings in C. Strcpy acts weirdly

The strcpy function works weirdly and I want to know what is happening. char name[] = "The Batman"; //10 characters char name2[5]; strcpy(name2, name); name is now changed for some reason. It is now "atman". Why is name changing over here? name2…
-4
votes
1 answer

Strcpy thru array subscribed

In the Ritchie/Kernighan book, they show a few ways how to create a self made strcpy function, one of them is with using array subscribed instead of char pointers , but when I try this method and run the code it only gives me the second word in this…
Steve Bob
  • 5
  • 5
-4
votes
1 answer

To many arguments in function

I'm writing a program that checks who the user is, if it's the correct user logged in it will upload data to my FTP server. It encrypts the data using tar, than openssl. I think that part is correct however when passing system commands to the…
N3Xxus6
  • 11
  • 2
-4
votes
1 answer

C pointer to pointer overwriting last one saved

What I want to do is take the string, save it into an array of strings and then modify each copy based on index. I edited the question and code, it was messy and unclear. As the question is almost the same (I think now it's more precise), I thought…
Eli
  • 3
  • 3
-4
votes
4 answers

What's wrong with my implementation of std::strcopy? (segmentation fault)

I'm encountering a run time error attempting to use std::strcopy with elements in a vector of std::string. There is no problem with the vector. I have higher level functions that work without a hitch. I'm running into an issue with my low level…
BuvinJ
  • 10,221
  • 5
  • 83
  • 96
-4
votes
1 answer

Does strcpy or strcat make unnecessary changes of the string when used within printf statement?

I ran this code: #include #include int main() { static char str1[] = "dills"; static char str2[20]; static char str3[] = "Daffo"; int i,j; i = strcmp(strcat(str3, strcpy(str2, str1)), "Daffodills"); printf("%d",…
Arnab
  • 19
  • 2
-4
votes
1 answer

Confused by C String

While learning C String, I had this code snippet:` char s[1]; strcpy(s, "hello"); puts(s); printf("sizeof(s) = %ld\n", sizeof(s));//the result is 1 printf("strlen(s) = %ld\n", strlen(s));//the result is 5 printf("s[4] = %c\n", s[4]);//print 'o' Why…
toantruong
  • 464
  • 1
  • 8
  • 16
-4
votes
1 answer

strcpy function behaviour

I have run the below program: #include #include #include int main() { char *p, *q; p = (char*)malloc(1); q = (char*)malloc(25); strcpy(p, "abcd"); strcpy(q,"efgh"); strcat(p,q); …
Sarwan
  • 595
  • 3
  • 8
  • 21
-5
votes
1 answer

strcpy compiles on Windows but it doesn't on Linux

I'm learning C++ and trying to write universal code (sorry, I don't know how you call the code that can compiles on Windows, Linux, MacOS, etc.). I have written the function trimLeft: #include #include #include using…
VansFannel
  • 45,055
  • 107
  • 359
  • 626
-5
votes
2 answers

How to backup strings in C

How can I back up the string in its original form? I'm using strncpy() but, however when I try to print the sentence the original text is altered. Here is an example: if I entered "This is a sample text" for gets and ask to print the sentence, the…
Rak
  • 9
  • 3
-5
votes
3 answers

strcpy cause Program received signal SIGSEGV, Segmentation fault

I have the following codes: int main(int argc,char * argv[] ) { char* SourceWeightFiel; char* TargetWeightFile; strcpy( SourceWeightFiel, argv[1] ); strcpy( TargetWeightFile, argv[2] ); return 1; } when I debug it in gdb, it's Ok in…
greenleaf
  • 791
  • 1
  • 7
  • 11
-5
votes
3 answers

Why Strcpy function is not working with Pointer to Array?

I am learning about Pointers. This piece of code is producing run time error. I am trying to insert string in char array using Pointer to char. #include #include int main() { char *a[10]; strcpy(*a,"foo"); }
-5
votes
2 answers

Infinite loops in C

I'm pretty sure this this piece of code gives me an infinite loop, (I have left if for a very long time and nothing happens), and I've been starring at this for 2 days now and i don't have a clue why it keeps looping. Any ideas? int r = 0; …
J.doo
  • 11
  • 3
-5
votes
3 answers

use strcat with strcpy occur problems

I have a problem when use strcat function. I have no idea.please help me.thanks char dst[5]="hello"; char *a = "12345"; char *b = "54321"; //work strcat(strcpy(dst, a), b); printf("one==%s\n",dst); //error strcpy(dst, a); strcat(dst,…
cowry chen
  • 11
  • 1
-6
votes
2 answers

C : how do I printf "the square root of 1764 is 42 and * in ascii"?

ok so I am learning C and I try to use simple functions to understand basics and here I am stuck whith a segmentation fault I can't manage to make this code working h3lp please thanks you all !!! #include #include int …
CnewB
  • 1
  • 3
1 2 3
63
64