strcpy Questions

3

Solved

#include <stdio.h> #include <string.h> int main() { char src[]="123456"; strcpy(src, &src[1]); printf("Final copied string : %s\n", src); } When I use the Visual Studio 6 Comp...
Kayne asked 18/12, 2014 at 12:32

4

Solved

My understanding is as follows: char * points to a string constant, modifying the data it points to is undefined. You can, however, change where it points to. char[] refers to a block of memory t...
Russellrusset asked 26/8, 2014 at 9:55

2

Solved

Is memcpy() usually faster than strcpy() (on most real platforms)? (I assume that size of the string is known.) If I remember i386 assembler correctly, there are loop instructions which copy a giv...
Benzvi asked 26/7, 2014 at 1:42

3

Solved

I am a beginner, and I am learning how to copy a string in C now. Here is a problem I just met: Every time I try to use "strcpy" command to copy from string 1 to string 2, Visual Studio 201...
Carnelian asked 26/4, 2014 at 23:31

17

Some people seem to think that C's strcpy() function is bad or evil. While I admit that it's usually better to use strncpy() in order to avoid buffer overflows, the following (an implementation of ...
Zebada asked 4/3, 2009 at 11:54

7

Solved

I have recently started programming in C, coming from Java and Python. Now, in my book I have noticed that to make a "Hello World" program, the syntax is something like this: char message[10...
Hyoscyamus asked 5/2, 2013 at 14:3

6

Solved

Background: I have a small routine that mimics fgets(character, 2, fp) except it takes a character from a string instead of a stream. newBuff is dynamically allocated string passed as a parameter a...
Kovar asked 28/1, 2011 at 0:48

2

I have a question about using strcpy. I know the ANSI C standard says : source and destination must not overlap, otherwise the behaviour is unpredictable. I show you a piece of code that works as I...
Lodhia asked 17/10, 2012 at 13:25

3

Solved

I am wondering why am I getting segmentation fault in the below code. int main(void) { char str[100]="My name is Vutukuri"; char *str_old,*str_new; str_old=str; strcpy(str_new,str_old);...
Grandeur asked 26/4, 2012 at 2:53

4

Solved

I am writing to a binary file using a struct that just contains a char[32]. I basically need to format each block of data by performing various calculations on string arrays and concatenating the r...
Waldack asked 1/12, 2011 at 17:28

4

Solved

The second arg in the prototypes for memmove/memcpy/strcpy are similar: For example: void *memmove(void *dest, const void *src, size_t n); //const void* char *strcpy(char *dest, const char *src); ...
Histogen asked 16/9, 2011 at 13:23

3

Solved

hello I have a code like the one below char *str ; strcpy(str, "\t<"); strcat(str, time); strcat(str, ">["); strcat(str, user); strcat(str, "]"); strcat(str, "("); strcat(str, baseNa...
Serilda asked 31/8, 2011 at 8:51

2

I have a character array defined as follows: char *c[20]; I'm trying to do: strcpy(c[k], "undefined); but it's not working I've also tried defining it as char c[20][70] with no luck. Edit: I actu...
Insentient asked 31/8, 2011 at 0:25

5

Solved

Why does the below C code using strcpy work just fine for me? I tried to make it fail in two ways: 1) I tried strcpy from a string literal into allocated memory that was too small to contain it. I...
Potsdam asked 21/8, 2011 at 17:29

4

Solved

I know that you will rap me over the knuckles but. Why does it make Segmentation fault char* cmd; strcpy(cmd, argv[0]); when this doesn't char *cmd; cmd = "plop"; I didn't practice since a w...
Gabbard asked 22/6, 2011 at 23:31

3

Solved

I have a global structure: struct thread_data{ char *incall[10]; int syscall arg_no; int client_socket; }; and in main() char buffer[256]; char *incall[10]; struct thread_data arg_to_thread;...
Madriene asked 9/6, 2011 at 5:56

6

I'm perplexed as to why the following doesn't work: char * f = "abcdef"; strcpy(f, "abcdef"); printf("%s",f); char s[] = "ddd"; strcpy(&s[0], "eee"); printf("%s", s); In both examples strcp...
Exceptional asked 13/4, 2011 at 7:43

6

Solved

Is it safe to do something like the following? #include <stdio.h> #include <malloc.h> #include <string.h> int main(void) { char* msg; strcpy(msg, "Hello World!!!"); //<---...
Isolative asked 18/3, 2011 at 16:25

5

Solved

Does a string created with 'strcpy' need to be freed? And how to free it? Edit: The destination is allocated like this: char* buffer[LEN];
Marrowfat asked 20/2, 2011 at 22:49

4

Solved

In C i used strcpy to make a deep copy of a string, but is it still 'fine' to use strcpy in C++ or are there better alternatives which i should use instead ?
Anaglyph asked 20/1, 2011 at 19:14

1

Solved

What would be the best way to copy unsigned char array to another? For example: unsigned char q[1000]; unsigned char p[1000]; strcpy (q,&p); The above code does not work, it gives me error...
Bestir asked 22/12, 2010 at 7:56

9

Following is the most popular implementation of strcpy in traditional systems. Why dest and src are not checked for NULL in the start? I heard once that in old days the memory was limited so short ...
Perceptive asked 1/9, 2010 at 8:40

7

Solved

I am trying to understand the difference/disadvantages of strcpy and strncpy. Can somebody please help: void main() { char src[] = "this is a long string"; char dest[5]; strcpy(dest,src) ; prin...
Hare asked 21/10, 2009 at 15:53

9

Solved

The first example does not work when you go to delete the pointer. The program either hangs when I add the null terminator or without it I get: Debug Assertion Failed Expression: _BLOCK_TYPE_IS_VA...
Jellaba asked 16/10, 2009 at 12:29

7

Solved

The clue is in the title but basically I've inherited some code which has 800+ instances of strcpy. I want to write a new function and then to replace strcpy with strcpy_mine. So I'm trying to work...
Jenifferjenilee asked 4/6, 2009 at 14:57

© 2022 - 2024 — McMap. All rights reserved.