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

comparing string to words in an array

I got an assignment from my teacher to write a code that compares a given word to a bunch of words located in an array of strings. If the word in the array is lexicography smaller than the word given, I need to put it inside a new array. else, I'm…
Kfir Bilu
  • 29
  • 8
-1
votes
2 answers

I have encountered "Buffer overflow-array index out of bounds" error

I do understand the error but don't know what is the proper solution for this. It says Array 'filename' of size 512 may use index value(s) MIN..1022 Is it because strncat is called right after strncpy? I tried doing strlen, but that introduced…
-1
votes
1 answer

Access violation strcpy

Whenever I call strcpy to make "SendEmail.exe " + log[1024] into a LCSTR I get a runtime violation exception. I tried debugging and it hit the line: strcpy(CmdParams, ""+log[1024]); char log[1024]; ... if (strlen(log) > 49) { STARTUPINFO si; …
dxdxxdd
  • 17
  • 1
-1
votes
1 answer

Getting an "L buffer is too small && 0" error from strcpy_s -- trying to make an overloaded + operator

I'm trying to write a simple version of the string class (for practice), and I have everything working except the overloaded + operator. The line " strcpy_s(temp, strlen(stringPtr) + 1, stringPtr); " keeps throwing an exception. I assume strcat_s…
Lee
  • 15
  • 4
-1
votes
2 answers

Segmentation fault when using strcpy()

We added print statements to check where the segmentation fault was happening. It fails at strcpy(command, token); How can we store that part into command? Also is there a way to check for the null character at the end of token? Does strtok() have a…
Brad Bieselin
  • 107
  • 1
  • 11
-1
votes
1 answer

Read access violation when attempting strcpy from file buffer to char array

I've been working on an assignment to implement hashing. In it, I read through a text file called "proteins". The problem occurs when I try to copy it to another char array. Visual Studio throws a read access violation. #include #include…
Noctimor
  • 3
  • 1
-1
votes
1 answer

C strcpy() breaks when it is inside a function but not on main()

I want to initialize an array of strings with the same value to every position. So i am trying this code: #include #include #include #include #define TAM_VETOR 1009 #define QTD_PLACAS 1000 void…
LRD27
  • 98
  • 1
  • 8
-1
votes
1 answer

How would I get convert this std::string into a std::basic string?

Currently I have a std:::string called cipher_line that I get from the process of: string str_cipher_line; // Get the Offline Mount Point ifstream ifs1; ifs1.open(offlineMountPoint.c_str()); if (ifs1.is_open()) { getline(ifs1,…
SDG
  • 2,260
  • 8
  • 35
  • 77
-1
votes
2 answers

C++ strcpy function fails in few major cases

When this code for swapping two string is being executed I get undesired outputs #include using namespace std; int main() { char a2[] = "Hello world"; char a1[] = "Geek"; char a3[20]; …
-1
votes
3 answers

Correct way to use strcpy() function?

What is the correct way to use strcpy() function? I have done it in two ways, and both times the program worked just fine, so I was wondering what's "more correct" way to use it. I want to copy string s2 to s1. This one: s1=strcpy(s1, s2); or…
Plexus
  • 143
  • 2
  • 13
-1
votes
1 answer

unexpected result in C strcpy and strncpy combination

In practicing for final exam in my high school, we got following question: Find values of strings s1, s2 and s3 after code executed: char s1[] = "Short Message Service", *s2, *s3; s2 = strchr(s1, 'M'); s3 = strrchr(s2,'S'); strncpy(s1 + 1, s2,…
-1
votes
1 answer

Getting Segmentation Fault error while performing strcpy

Getting the Segmentation Error whenever I am trying to perform the string copy. but the same code will work when I will do direct assignment. In the if statement, I am performing the strcpy operation, getting the memory corruption issue. Help me to…
Shrikant B
  • 25
  • 4
-1
votes
1 answer

C - Seg Fault on Strcpy()

I am trying the following to assign a value to key, which is part of a stuct. Key is a pointer to a char. T->oa[i].key = (char*)malloc(5*(sizeof(char))); strcpy(T->oa[i].key,"abc"); When I run this, I get a seg fault on the strcpy line. What is…
Austin
  • 347
  • 7
  • 21
-1
votes
1 answer

Values separated by any character not read correctly from string

Since my 8051 compiler doesn't have a feature that detects unused variables, I decide to try to implement my own, but it doesn't work. When the program runs, it successfully identifies all labels by reading the main file then for each label name, it…
Mike -- No longer here
  • 2,064
  • 1
  • 15
  • 37
-1
votes
2 answers

C Replace a string from a 2d char array using strcpy Issue

Why does it print out the new word minus the first character when i printf("%s\n",array[0]) and not "Hello". Any tips for how to do solve that ? Thanks in advance ! #include #include int main() { char newword; char…
Nick Green
  • 11
  • 3