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

Sorting 3 strings Lexicographically using conditionals in C

I cannot wrap my mind around doing this logically. I have mapped out all possibilities for sorting and based my algorithm on that. ABC ACB BAC BCA CAB CBA Only six possible combinations for 3 strings, and so, I thought it a very quick and easy…
compute
  • 75
  • 9
0
votes
0 answers

strcpy not copying char array to char pointer

void processWord(char * word) { if(word != NULL) { char * temp = word; char final[32]; int index = 0; while(*temp) { if((*temp >= 65 && *temp<=90) || (*temp>=97 && *temp<=122)) { …
0
votes
1 answer

c- passing argument 1 of 'strcpy' from incompatible pointer tyle

I am trying to write a shell program and I have an inputBuffer array that holds the command that was entered. I also have a historyBuffer array that will hold the past 10 commands that were entered. I have the global variable: char…
JCP
  • 3
  • 6
0
votes
1 answer

Cannot sort command line arguments using strcpy

I am fairly new to C/C++ and I am learning command line arguments. I am trying to sort my command line arguments using strcpy, however it is giving me bad output. e.g. i/p : i am o/p : ami i Can anyone help me on what am I doing wrong…
siddyi
  • 23
  • 1
  • 7
0
votes
1 answer

Segmentation Fault in C using fgets(), strtok(), strcpy()

I am getting a seg fault from the code shown below. I am trying to create a simple database that reads a stdin from a bin file chops it up by commas, throws each value into an array and throws it in a struct. I want to do this for every line in the…
0
votes
3 answers

How to initialize string in struct without using strcpy function?

Is there any manual way to initialize the string in struct ? I used to initialize string in struct using strcpy function such as: typedef struct { int id; char name[20]; int age; } employee; int main() { employee x; x.age=25; …
0
votes
4 answers

strcpy function not working properly

Please consider the below code. #include #include void main() { char a[6], b[6]; strcpy(a,"rajeev"); printf("print A:"); for(int i=0;i
Anjali
  • 59
  • 2
  • 9
0
votes
4 answers

Why malloc can't work with strcpy?

char * removeChar(char * str, char c){ int len = strlen(str); int i = 0; int j = 0; char * copy = malloc(sizeof(char) * (len + 1)); while(i < len){ if(str[i] != c){ copy[j] = str[i]; j++; …
Nina Liu
  • 33
  • 2
0
votes
1 answer

Sorting a pre-defined list of names

I'm working on Chapter 8 Challenge 3 from C Programming for the Absolute Beginner 2nd Edition. The program is supposed to sort an array of names alphabetically. My program doesn't work. The main function without sort() works, but the sort function…
dexter27
  • 3
  • 1
0
votes
0 answers

strcpy in array of strings

I am trying to make a function which puts '.' characters in each string of an array, to complete them to n characters. And it is working fine, except that i cannot copy the tmp sting to the string in the array neither with strcpy, nor with…
0
votes
1 answer

Segmentation fault when doing strcpy

I've started to learn C and I've been working on some small programs to learn. Right now I'm at the point with memory pointers and I have a quick question. As I understand it, the program I've written below navigates to the /proc/sys/net/ipv4/conf/…
0
votes
1 answer

Using passed-in array to initialize other array

I am trying to "initialize" an array that I have made in my class declaration and I do not know what I am doing wrong. I understand that when you pass an array into a function, it decays into a pointer to the first character. The code breaks on my…
0
votes
2 answers

segmentation fault on strcpy();

#include #include #include #include #include #include #include #include #include #include #include typedef…
jhowe
  • 3
  • 1
  • 3
0
votes
2 answers

Copy an array of string in C

I'm making a program which sorts some input words according to some rules. To allign them, I'd like to copy "words" to "tmp" by using memcpy to use and change "tmp". I tried to declare tmp to double pointer or array, but the only I met was…
beginner
  • 11
  • 1
  • 4
0
votes
2 answers

I new to programming and study about operator overloading. To overload "+" to add two string

I new to programming and study about operator overloading. To overload "+" to add two string. But when I try to combine two string using strcpy, the second string replace the first string instead of copy with first…