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

incompatible type for argument 2 of ‘strcpy’

I was hopping someone can help me with my C code. I'm getting this error: error: incompatible type for argument 2 of ‘strcpy’ strcpy(tmp, (SB->jNodes[j])); Here's my code for where the error happens: for (int j = 0; j < 20; j++) { iNode…
Nicky Mirfallah
  • 1,004
  • 4
  • 16
  • 38
0
votes
1 answer

how can strcpy function accept both adress as well as string constant?

void main() { char str1[10], str2[10] = "haha"; strcpy(str1, str2); puts(str1); strcpy(str1, "tictoc"); puts(str1) ; } how can adress as well as string constant passed to a pointer variable through pre-defined strcpy function…
0
votes
0 answers

Why does strcpy work in the first for-loop, but not the second?

So to start this off, this is not the complete program. I am working on it and just ran into this problem. The first 3 times I call strcpy (in the first for-loop) it compiles without problem. However, the fourth through sixth times (in the second…
0
votes
1 answer

Strcpy Null Value Obtained From MySQL in C

I am using Connector C to connect to my MySQL database. A modification that I have made to the database recently now allows the data in my url field to be NULL. Connector C does not appear to have any problems reading the NULL value, but when I try…
sax
  • 337
  • 1
  • 14
0
votes
1 answer

MIPS Concatenating String Code not working as intended

I'm a begginer at MIPS and I'm having trouble with a concatenation program I have. The code I wrote is here # _strConcat # # Concatenate the second string to the end of the first string # # Arguments: # - $a0: The address of the first string # -…
ELlama
  • 33
  • 7
0
votes
2 answers

Error Segmentation fault (core dumped)

I am doing some exercises for my university course on C and I have the following code which exits with error Segmentation fault (core dumped) after the user has input the choice (1 or 2). I don't know if it's an issue that I am using ubuntu 16.04…
Danae Vogiatzi
  • 178
  • 5
  • 23
0
votes
1 answer

How to prevent strcpy from overwriting another variable as well?

I'm trying to make a simple code that converts one type of data into another. I use strtok to extract one part of the data and then I run a long serial of if conditions to find the right output. However, when the correct output is found and written…
Pacific
  • 3
  • 3
0
votes
1 answer

Why strcpy doesn't work but direct assign works?

In the following code: #include #include #include typedef struct { char** tab; int n; }slist; void print(slist* p); void add(slist* p, const char* s); void add(slist* p, const char* s) { if(p->n==0) …
0
votes
2 answers

How to change a preexisting pointer in C

I am trying to create a char* strcpy(char* dest, const char*) function. This is what I have so far: char* mystrcpy(char *dest, const char *src) { char* tempsrc = (char*) src; int length = strlen(src); char tempdest[length]; for(int…
rdennis42
  • 25
  • 6
0
votes
2 answers

Array of Strings Manipulation in C

What is the best way for one to iterate through a mutable array of strings? For example: struct Book{ char chapter_names[20][50]; int chapters; ...} int main(){ struct Book Redwall; strcpy(*chapter_names, "The Wall"); …
David
  • 89
  • 9
0
votes
6 answers

Error with strcpy and its second argument

When I try and compile this program, I get errors (included below the code) about strcpy's second argument. I'm honestly stumped on what to do to fix it. And I'm sorry if my code is not efficient or pretty to look at; I'm just a beginning CS…
sk8bum
  • 11
  • 1
  • 5
0
votes
1 answer

Is there any error when deleting a row (of character) in 2D array, with `strcpy`?

I am a newbie to programming. I write this simple code to delete a row (of character) in 2D array: #include #include #define M_RW 100 #define M_CH 100 void ArrIn (char a[][M_CH], int &n) { for (int i = 0; i < n; i++) …
k312979
  • 19
  • 1
0
votes
2 answers

Invalid conversion from 'char' to 'const char*' while using strcpy

Can't use strcpy, to properly swap char array. I used strncpy, memcpy everything and still didn't get the right result. This is how my program looks. class Carte { protected: char Denumire[50]; char Autor[50]; char Editura[50]; int…
Lame Fanello
  • 545
  • 1
  • 6
  • 15
0
votes
1 answer

why strncpy is able to copy source string even if destination buffer is zero?

int main() { char src[] = "santosh"; char dest[0]; strncpy(dest, src, 4); printf("%s\n", dest); // expecting o/p "sant" but o/p was "santtosh" int i = 0; while (dest[i]) { printf("%c", dest[i]); //expecting output…
0
votes
1 answer

Overflow saved RIP register value with short address

I'm trying to do buffer overflow where I need to rewrite the saved RIP register value with an address. The address is short (8 bytes), for example, 0x0000000012345678. The RIP register is 16 bytes, but if I input 0's, it terminates the string…
Austin
  • 6,921
  • 12
  • 73
  • 138