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

How do I get all elements from a struct array, and add them into a string in c?

char str[vector_total(&final_clause)]; for(int i = 0; i
1
vote
4 answers

implementing a strcpy() function without using in C

My task is like this: I should implement the strcpy function under the following constraints: The function should use pointer expression (*(d+i)) I should implement it without using I'm programming in Visual Studio 2019. I searched some…
1
vote
2 answers

How do I return and print out the starting address of the first string (string1)?

I first copy the second string into the first string. Then I would return string1 pointer from the function. Then I use %p and (void*) to print out the starting address of the first string. Is this the right approach? printf("address: %p \n",…
1
vote
1 answer

error: expression is not assignable (to part of C pointer)

I am getting this error: error: expression is not assignable *fullmsg+(fmsglen+10) = output; for trying to assign a string pointer to a part of another string pointer. Why is this happening and how can I fix this?…
Serket
  • 3,785
  • 3
  • 14
  • 45
1
vote
4 answers

Help with c errors

getting this error: 1>c:\users\b1021568\documents\visual studio 2010\projects\tarefa42\tarefa 42\main.cpp(112): error C2664: 'cria_aluno' : cannot convert parameter 2 from 'const char [7]' to 'char' 1> There is no context in…
1
vote
2 answers

Request for an explanation of a program which uses the getchar() in a while statement

Will it be too much to ask if I pray for an elucidation of the following codes from Line 7 onward? I have difficulty in comprehending how getchar() may differ from gets() or scanf() for the most parts. Why is it important to add an escape sequence,…
Bao
  • 25
  • 1
  • 1
  • 10
1
vote
4 answers

C: How to copy over null terminator to structure member, in cleaner way?

Essentially I am tokenizing a string and strncpying the string found to a structure member, i.e. stringid. It of course suffers from the problem of lack of termination, I have added an extra array space for it, I've no clue how to add it properly. I…
Kenshin R.
  • 117
  • 1
  • 5
1
vote
2 answers

Segmentation fault when strcpy to struct

I have the following code: struct argument { char *source; char *destination; int value; }; int main(void){ struct argument *arg2 = malloc(sizeof(struct argument)); strcpy(arg2->source, "a1"); //This gives segmentation fault. …
Pengibaby
  • 373
  • 2
  • 11
1
vote
1 answer

Why does the compiler issue : warning: assignment makes integer from pointer without a cast

I'm trying to put some information into a 2d char array. I'm putting a list of names in stdin that i'm trying to put into an array with a number corresponding to the array of characters(names). For some reason, when I try to print the names, it…
1
vote
3 answers

strtok and strcpy error

I used strtok to split a string. [UPDATE] I used your comments and answer for the new version below, but didn't work atm int Crawl :: splitUrl(char ***tmp, int max_length, char *url) { int idx=0; char * p; int i; p = strtok (url,"/"); while (p…
Roby
  • 2,011
  • 4
  • 28
  • 55
1
vote
1 answer

Invalid write of size 1 when using strcpy to calloc'ed location

I'm trying to parse a given string into an array of NULL terminated commands, since I'm designing a C shell. So my desired command structure is : // Null terminated commands char** command1 = {"ls", "-l", NULL}; char** command2 = {"wc", NULL}; //…
fatima
  • 21
  • 3
1
vote
3 answers

Cant copy a string to a string in a struct ( C )

I am trying to copy some strings to strings in a struct using strcpy. I am posting the code: #include #include #include #include typedef struct floating_point{ char sign[2]; char exponent[9]; char…
Alptugay
  • 1,676
  • 4
  • 22
  • 29
1
vote
1 answer

Clang compiler auto-changed strcpy to memmov. macOS

When I compile with Clang on macOS (with or without xCode), the call into strcpy is auto-substituted to memmov. Is there a Clang flag to turn this off? int main(void) { char nice_message[6]; const char *message = "hello"; …
rustyMagnet
  • 3,479
  • 1
  • 31
  • 41
1
vote
3 answers

Is this a good way to use strcpy?

I try to use strcpy; is it a good way to do so? char *stringvar; stringvar = malloc(strlen("mi string") + 1); strcpy(stringvar, "mi string"); stringvar[strlen("mi string")] = '\0'; What do you think?
Roman
  • 47
  • 4
1
vote
3 answers

How do i copy a string that has been dynamically allocated to another string that has been dynamically allocated?

I am having trouble trying to implement a custom strcpy function which is supposed to handle cases where the src string is larger than the destination string. Here I have provided some code so that you guys can see the entire function. My issue is…