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

what would be the output of this code, it uses strcpy in a constructor?

Hello I have question about some code. Is this code supose to work as it is here? I thought I would need to use #include cstring I asked my teacher and he told me that the code is good as it is and that it should work with #include string Is this…
juan
  • 113
  • 4
1
vote
3 answers

C - split string and enter into array

I am currently trying to handle string in C and I am having trouble placing the split values of a string into an array. Bellow is the code I have created in an attempt to achieve this. #include #include int main(){ …
Dylan Edmonds
  • 47
  • 1
  • 6
1
vote
3 answers

Why does this implementation of 'strncpy' work?

I have to rewrite for an assignment a function that mimics the behavior of the strncpy, after many trials and error, some external help, here's the final code : 15 char *ft_strncpy(char *dest, char *src, unsigned int n) 16 { 17 unsigned…
Jib
  • 45
  • 1
  • 5
1
vote
2 answers

getting the local system date time and converting it to a string (MFC C++)

I have inherited some MFC C++ code (it's an ActiveX OCX control running on a Windows Mobile 6.5 device) and I need to acquire the system date and time and append it as part of an existing string which gets passed via the com port to another…
C Williams
  • 11
  • 1
  • 2
1
vote
2 answers

initialising structs via function with strcpy in c

I am a beginner in c and am wondering why my function feed_struct doesn't copies the strings I handle to it. This funcion ( feed_struct) should take input data and put it in a struct, which I defined globally. Does anyone know why there happens…
Stokes
  • 13
  • 2
1
vote
1 answer

Tokening An External File

So I have been stuck as to how to token the FIRST token and place that value into a struct. In my case I am trying to read the lines from a file that looks like this: TDV format: TN 1424325600000 dn20t1kz0xrz 67.0 0.0 0.0 0.0 …
1
vote
4 answers

strncmp/strcpy corrupting source

today i was trying to get friendly with char * string... but it seems im failing :) Every time i call strcmp/strncmp/strcpy function my source gets corrupted... here is the snippet #include #include #include struct…
Alex
  • 13
  • 3
1
vote
1 answer

[C]: Segmentation fault using strcpy() into String Arrays

My assignment is to write a function that takes an input string from a user, tokenize it into several strings each containing an individual word from the input sentence, and then reverses the sentence. The result will be the sentence input but with…
1
vote
2 answers

strcpy giving segmentation fault

Consider the following code: #include #include #include char *cexpGen(); char *chartoStr(char c); char c_exp[] = "1"; char expressions[2] = {'+', '-'}; int main() { cexpGen(); printf("%s", c_exp); …
amirali
  • 1,888
  • 1
  • 11
  • 32
1
vote
2 answers

C string at the end of '\0'

While writing c code, I tried to write strcpy code of my own, and I faced this issue. #include #include void strcpy2(char *s, char *t); int main() { char a[10] = "asds"; char b[10] = "1234567890"; strcpy2(a, b); …
Hashnut
  • 367
  • 3
  • 18
1
vote
2 answers

Segmentation fault in my strcpy

I'm writing my own strcpy due to the fact that the default one in string.h only accept a const char * as a source string to copy from. I'm trying this very basic prototype (yes, the return isn't meaningful, I'm just trying things): int…
riciloma
  • 1,456
  • 2
  • 16
  • 31
1
vote
2 answers

Directory entries and linked lists

This is code to put directory entry strings (from the root directory, in this case) into a single-linked list. I do not understand why a seg fault occurs at the line commented as such. I must be doing the string copying wrong? I can only think that…
sid
  • 157
  • 8
1
vote
0 answers

strcpy in c is behaving different

I am trying to understand strcpy() function but I could not. As said in this page If destination string length is less than source string, entire source string value won’t be copied into destination string, Instead it will be truncated. But when I…
vicky
  • 2,119
  • 4
  • 18
  • 32
1
vote
1 answer

Segmentation error handling strcmp

I have the following code: #include #include #include #define RCVBUFSIZE 1024 void insertarOperacion(char *op){ char operacion[RCVBUFSIZE], *retrString = "RETR "; //< bool operacionError = false; …
boludo kid
  • 154
  • 1
  • 12
1
vote
1 answer

C++ Buffer is too small Error

Intermittently, Visual Studio throws an exception when running my code. I say intermittently because I've been able to successfully run my code without an error. The error was thrown after I created the function "print_Days." The exception thrown…
Chris
  • 191
  • 2
  • 12