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

Custom strcpy is compiling fine, but not working properly

I'm working on a C assignment that's basically making our own C String class. My partner and I are confident that we have the logic correct and our source files are compiling, but we're unable to get any output on a simple main file. Our strcpy is…
0
votes
1 answer

C++ strtok and 2d arrays. Program compiles but crashes

#include #using namespace std; #include #include int main(int argc, char *argv[] ) { ifstream file; // check for valid user input if (argc != 2) { cout << "Please enter the file name." << endl; return…
ryye
  • 315
  • 4
  • 13
0
votes
2 answers

C++(Visual Studio 2012): Copying a function's parameter char* to a dynamically allocated one

I have this structure defined and a class in my project. It is a class that holds id numbers generated by GetIdUsingThisString(char *), which is a function that loads a texture file into GPU and returns an id(OpenGL). The problem is, when I try to…
Vladivarius
  • 498
  • 1
  • 3
  • 14
0
votes
1 answer

buffer over flow i'm getting these error's

#include int main(int argc, char *argv[]) { char buffer[10]; strcpy(buffer, argv[1]); printf("%s\n", &buffer); } how ever i'm getting the gcc error warning: incompatible implicit declaration of built-in function 'strcpy and when I do gdb…
0
votes
1 answer

Getting a "char" while expecting "const char"

I wrote the the next code in the main: int main{ Employee *employee1 = NULL; char *empName1=NULL; char *workHours[7]; for (int ii=0;ii<7;ii++) { workHours[ii] = new char[5]; } if (empName1 != NULL) {delete…
0
votes
5 answers

How to separate an array and store it in a new array?

What I want to do is: The user inputs a string with commas; for example: 123456,44,55,,66 and I want to separate it and store in a new array without the commas; for example: m[0][]={123456}, m[1][]={44}, m[2][]={55}, m[3][]={}, m[4][]={66} 123456…
Michael Tan
  • 81
  • 13
0
votes
1 answer

Using strcat to append spaces. Compiles but overwrites string

The language I am working in is C. I am trying to use a mix of built in c string functions in order to take a list of tokens (space separated) and "convert" it into a list of tokens that is split by quotations. A string like echo "Hello 1 2 3 4"…
Clay Benson
  • 161
  • 1
  • 9
0
votes
3 answers

Segmentation fault (core dumped) when using with strcpy

I have following code which will print all the filenames from a given directory. But error is Segmentation fault (core dumped). I am not experienced using strcpy with pointers. skipping include extern int errno; typedef struct fileinfo { char…
pmverma
  • 1,653
  • 13
  • 27
0
votes
0 answers

strcpy() related segmentation fault

my problem is i have a program that runs on Windows perfectly while on Dev machine it gives segmentation fault without any output from my program.To test it ,i put a printf() at the start of main ,before any code piece and it still gave segmentaion…
0
votes
2 answers

Implementation of strcpy and strcat that deals with exceptions

I have to write strcpy() and strcat() in 7 lines of code and deal with any exceptions there could be. This is my code so far. Does anyone have any suggestions on how I can reduce the number of lines? char *mystrcpy(char *dst, const char *src) { …
0
votes
3 answers

C strcpy( ) does not cut char character

I am surprised, after writing and running following C++ code below on Red Hat Linux. #include #include #include using namespace std; int main() { char natureofGoods[17]; char *name="sadasdasdasdas171212"; …
beterman
  • 101
  • 1
  • 10
0
votes
6 answers

fast padded strcpy for a single word

I'm trying to write a very cheap C++ code snippet to do the following operation on a short null terminated string. The input is a string like "ABC". It is null terminated and has maximum length of 4 (or 5 with the null terminator). The output goes…
E_G
  • 327
  • 3
  • 9
0
votes
3 answers

why does this simple strcpy(...) cause a segmentation fault?

I'm not understanding something simple. I have this sample code: typedef struct { char* fname; } PersonType; int main() { PersonType *p; p = (PersonType *)malloc(sizeof(PersonType)); char * name = "Robert"; /* this next line causes a…
user550738
0
votes
4 answers

Segmentation fault when using strcpy() with pointer to cstring

int main(int argc, char* argv[]){ // checked for right number of arguments // reading pack name char* filename[MAX_STR_LEN]; strcpy(*filename, argv[1]); // seg fault here }
0
votes
2 answers

Am I using strcpy_s incorrectly?

I have a constructor for a Person class called "Person" it looks like this: Person(const char * their_name, const char * email, int day, int month, int year) : name(0), email_address(0), birthday(day, month, year) { name = new…
Sarah
  • 2,713
  • 13
  • 31
  • 45