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

There is some problem with null character termination in this code

#include #include #include int main(){ char *str = (char*)malloc(4); strcpy(str,"aaab"); char *pt; strcpy(pt,str); while(pt != NULL){ printf("%c",*pt); pt++; } } I wanted…
0
votes
1 answer

strcpy access private object in class

I'm reading data from a file in JSON format, and I want to put the values in the objects password_c and apiKeyValue members: class Configuration { private: char password_c[32]; char apiKeyValue_c[20]; public: String get_ApiKeyValue(); …
Mateus
  • 1
0
votes
1 answer

too few arguments in invocation of macro "strcpy" - C VSCode

For some reason, the following code compiles and runs fine, but after adding the C/C++ VsCode extension, I get a syntax error saying that there are too few arguments. For background, I am receiving a user input in main, passing the string to the…
koncameron
  • 25
  • 5
0
votes
1 answer

How can I fix this error which causes my other string not to print?

I am trying to run the program below where one contains a date and the other contains the clothes in an outfit. The date structure works fine, but the one about the outfit results in the following error: main.c: In function ‘main’: main.c:41:5:…
0
votes
2 answers

QEMU for AArch64: why execution stucks at "ldr q1, [x0]"?

I have this simple C code: #include "uart.h" #include char x[32]; __attribute__((noinline)) void foo(void) { strcpy(x, "xxxxxxxxxxxxxxxxxxxxxxxx"); } int main(void) { uart_puts("xxx\n"); foo(); uart_puts("yyy\n"); } compiled…
pmor
  • 5,392
  • 4
  • 17
  • 36
0
votes
1 answer

passing argument 2 of 'strcpy' makes pointer from integer without a cast [-Wint-conversion]

char getString(char *str, int length, char field[20]) { printf(" %s: ", field); fflush(stdin); fgets(str, length, stdin); str[strlen(str) - 1] = '\0'; fflush(stdin); return *str; } why i can't use strcpy in this…
nomnom
  • 17
  • 4
0
votes
1 answer

Basic use of strcpy_s , strcat_s

Code char* CreateString(char* string1, char* string2) { int length = strlen(string1) + strlen(string2); // Allocate memory for the resulting string char* result = malloc((length) * sizeof(char)); // Concatenate the two…
0
votes
2 answers

Why does pointer to custom struct doesn't work here?

Why pointer to custom struct doesn't work in that code? Why I'm getting warning in that line with p->x = x? Why I'm getting second warning in line with strcpy_s? #include #include #include #include…
Freezend
  • 3
  • 1
0
votes
1 answer

How can you copy a string to non-accessible memory?

char* argv[MAXARGS]; char* buf2=malloc(MAXLINE * sizeof(char)); strcpy(buf2, buf); //buf is string with some words char* ptr = strtok(buf2, " "); argv[0]=ptr; strcpy(argv[0], ptr); free(buf2); Like above, I want to copy value of ptr to argv[0]…
newb hi
  • 39
  • 5
0
votes
1 answer

I don't understand why am I getting this output in this C program

#include #include int main(void) { char s1[6] = "Hello"; char s2[3]; strcpy(s2, s1); printf("%s\n", s2); return 0; } I have written this code in C and expected the output to be either an error or…
Joe
  • 19
  • 4
0
votes
1 answer

How do I allocate an array of string in an array of structure

I'm trying to allocate the char** path array in my batiment struct #ifndef SDL2_BATIMENTS_H #define SDL2_BATIMENTS_H typedef struct{ int x; int y; }vecteur; typedef struct{ int numtype; //Détermine quelle representation du…
0
votes
1 answer

Why strcpy() copies every string to first index of 2d array

I have a problem with filling a 2d char array with strings from a text file. I am trying to fill 2d array with specific strings from my file, but when I try to print out the first string at position 0 I get all strings connected as if they were one…
0
votes
0 answers

Segmentation fault when initializing a 2d array inside function and using strcpy on it

I want the textfiles array emptied after each function call so initialized it inside the function but im now getting a segmentation fault. Ive looked at other questions regarding this problem but couldnt find what i was looking for. void…
user20137453
0
votes
1 answer

Incompatible pointer type file txt for loop

I am getting an error for the below code. I was wondering if I am missing memory allocation or what could be the pointer issue. Any help would be wonderful , thank you #include #include #define MAX_ITEM_NAME_STRING 25 #define…
Nikki
  • 31
  • 5
0
votes
1 answer

c: using strcpy() on an element inside a data structure

i am currently learning cs50. i am currently studying data structures..i came across a problem...please see if you could help: #include #include #include struct node{ char *name; int age; }; typedef struct node…
hussein
  • 11
  • 2