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

What's wrong with this code

Somebody told me that this piece of code has some serious issues but I have not been able to get my head around such issues. Can you guys please educate me on this? static char BASED_CODE szFilter[] = "HTML Files (*.xls)|*.xls|All Files…
0
votes
1 answer

How to separate specific data

I am trying to extract the city from the following string; Kmart, 200 Irwin Ne, Fort Walton Beach FL The code I made goes through the string and I can extract this; Fort Walton Beach FL However, I do not understand how to effectively extract the…
thn
  • 3
  • 3
0
votes
1 answer

How to get specific data from text line

I am trying to get the address of a certain line in a text file. This line contains the following; Kmart, 7055 East Broadway, Tucson AZ I am using strcpy and strtok functions to extract the address (7055 East Broadway), but so far I've only been…
thn
  • 3
  • 3
0
votes
1 answer

Child doesn't terminate correctly in fork

I am writing a c program for a class that is a small shell. The user inputs a command, and the code executes it using the exec() function. I need to have a fork in the process so all the work is done in the child process. The only problem is…
gdawgrancid
  • 640
  • 3
  • 15
  • 37
0
votes
1 answer

Assigning value to a character array in a struct

I am trying to assign a Character array in struct using a string literal as shown below but it is not working: s1.name[20] = "Mark";//prints some garbage string with special symbols But when I tried assigning it using strcpy its working fine. Could…
sandywho
  • 353
  • 1
  • 7
  • 16
0
votes
0 answers

Using strcpy() to copy a string into a struct, when memory is allocated using malloc()

Currently in my program I have the user enter both a Song Title, and Artist Title for some songs. Each string is stored in an array. I am then trying to use those entered strings in a function to allocate memory by using malloc(), then use strcopy…
RocktheFries
  • 221
  • 2
  • 10
0
votes
1 answer

Understanding strcpy and char arrays in C

Why does strcpy work in the following example using a 2d character array: int main(void) { char words[2][6] = {"Hello", "World"}; strcpy(words[0], words[1]); printf("%s \n", words[0]); } But causes a segmentation fault in this example…
Ishmael7
  • 172
  • 1
  • 10
0
votes
4 answers

Trying to copy the remainder of a string after a character

I am trying to copy the remainder of a user inputted string. It is always input in the following: airport, 00:00, 00:00. The numbers are flight times and layover times. In my code I've gotten it to spit out the airport, but trying to use strchr to…
RocktheFries
  • 221
  • 2
  • 10
0
votes
0 answers

Using strcpy to copy part of a string after a certain character

so I'm having the user input a destination, flight time, and a layover time. The input will always look like "destination, 0:00, 0:00" and I'm trying to copy the input and reprint it. I have some function to ensure its inputted in the proper format,…
RocktheFries
  • 221
  • 2
  • 10
0
votes
0 answers

Why DOESN'T strcpy cause a segmentation fault when writing to a shorter array?

I'm trying to understand c strings and pointers better. I was playing with strcpy, and I expected the code below to cause a segmentation fault, but to my surprise, it did not. char a [] = "hello there"; char b [] = "yay"; strcpy(b,…
Brionius
  • 13,858
  • 3
  • 38
  • 49
0
votes
1 answer

Program always indents after printing char array?

I have an assignment to write a program that can be used in the bash shell that mimics certain default Unix commands, and we are supposed to build them from scratch. One of these commands is the PS1 command, which is supposed to change the $ prompt…
Jason Matthews
  • 65
  • 1
  • 1
  • 6
0
votes
2 answers

C triple pointers: Unable to copy string into position triplepointer[x][y] with [x] being greater than 1

I'm trying out triple pointers for the first time. This question is where I got the info on how to allocate a triple pointer and this is how the triple pointer has been allocated: //In this case size will always be 4 int size =…
0
votes
2 answers

What will empty string copy to another string?

I've just started to learn C programming. When coming to the String, I get confused with the function 'strcpy'. I tried switching places of first argument and the second argument. When I run the program, it just shows a 'S'. What does that…
Vincent.N
  • 141
  • 1
  • 10
0
votes
2 answers

Declaration unexpected behavior

So I have two simple programs. They are very similar, but one code works just fine and other one doesn't work at all. Does anyone here idea why? This code works without problems, despite char* name not being initialized. #include…
Zeljko M
  • 1
  • 2
0
votes
2 answers

Can strcpy edit memory addresses themselves on Arduino?

I'm parsing char arrays from the serial bus and copying their contents into global arrays for handling into other functions. I'm noticing odd behavior when I use strcpy() and strtok() repeatedly. With the Arduino Mega, can repeated calls to strcpy…