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
1 answer

My returnList[0] gets rewritten to @5'

I am trying to return an array of strings and while I copy the strings something weird happens when it passes the 4th index. For example, when it loops through the first 3 times it is stored as "the" but then it sudden becomes rewritten but it…
0
votes
2 answers

Why is this compiling withouth errors?

I'm a complete noob at C and i need some help understanding why a certain piece of code compiles correctly. main(){ char name[3]; strcpy(name, "12345678912312"); printf("%s\n",name); } So this code compiles correctly;however, I don't…
0
votes
4 answers

C Does strcpy needs specific buffer size or will still work?

I decompiled a application and I don't know the real array size so I made it pretty big but I wonder do I need to make exactly what I know it's going to be before the strcpy is used or must I consider the size of the strcpy as well? signed int…
user3435580
  • 566
  • 1
  • 4
  • 15
0
votes
3 answers

Copy element i in array to another array

How can I copy a char to an array? char s[100], p[100]; in = fopen("infix.in","r"); while (fscanf(in,"%s",s) != EOF) { for (j = 0; j < strlen(s); j++) { if (s[j] - 48 >= 0 && s[j] - 48 <= 9) { for (i = j; i < j + 1; i++) { …
0
votes
3 answers

strcpy and string presentation in memory

I have a program like this(x86_64 GNU/Linux) int main() { char s[] = "123456789"; char d[] = "123"; strcpy(d, s); printf("%p, %0p\n", s, d); printf("%s, %s", s, d); return 0; } and the output is : 0xeb6d2930 0xeb6d2910 …
bigpotato
  • 211
  • 2
  • 3
  • 13
0
votes
2 answers

Copy char array into array of character pointers

I am having problems trying to copy the contents of a char array into an array of char pointers in C. My code is listed below: # include # include # include # define RECORD_SIZE 300 # define BUFFER_SIZE 3 /* Structure…
Donald
  • 1,300
  • 2
  • 13
  • 29
0
votes
1 answer

Getting segmentation fault strcpy

struct Object * newObj(char * nome, int idade, float altura) { struct Object *obj = (struct Object *) malloc(sizeof(struct Object)); strcpy(obj->nome, nome); // This is the line obj->idade = idade; obj->altura = altura; return…
Erick Filho
  • 1,962
  • 3
  • 18
  • 31
0
votes
3 answers

Convert string to array, strcpy don't work

i tryed to use this algorithm to convert a string to an array. the problem is this: strcpy don't work. i tried also: strcpy_s strncpy memcpy --> with this function my array can print only the 1st word ( dunno why )... string tmp; getline(cin,…
0
votes
2 answers

Retrieving / comparing strings in file with user text

I am new to C and am looking to write a program that checks if a word that a user enters is a legit word. I've scoured stackoverflow for suggestions but many are very specific to a particular case. Please before I get flamed, I am aware that this…
Andy
  • 275
  • 2
  • 14
0
votes
1 answer

Using the C++ strstr function to remove the part of the substring your are searching for

I have an exercise question in class that has me stumped which is write a function named strCut that receives two C-style string parameters s and pattern. If the pattern string is contained in s, then the function modifies s such that the first…
user2027757
  • 13
  • 1
  • 6
0
votes
2 answers

C - segmentation core dump on strcpy()

I get a segmentation fault each time I'm trying to run this function. char *hist_array[20]; int history_counter = 0; void save_to_history(char *temp){ temp = malloc(512);/*512 is the size of temp array*/ printf("temp = %s\narray =…
Vitalij Kornijenko
  • 559
  • 1
  • 10
  • 22
0
votes
1 answer

How can I implement strcpy() and sorting of a struct in C?

I am making a small ANSI C application using GCC in Ubuntu which uses strcpy() and sorting. My header: #include #include #include #define DECKSZ 52 typedef struct card { enum {ACE=1, TWO, THREE, FOUR, FIVE, SIX,…
Benjamin
  • 345
  • 2
  • 3
  • 15
0
votes
1 answer

Mips String Length, Concatenation and Copy-Display is Wrong

I am writing a Mips Assembly code for extra credit in my Computer Organization and Assembly Class. We are to take three strings(S1, S2, S3). Then we concatenate the three strings into another(S4 = S1+S2+S3). We also copy this string, so that S6 =…
user3408013
  • 1
  • 1
  • 1
0
votes
1 answer

NASM issue on strcpy to launch firefox

I made the function strcpy in assembly, then I tried to launch several program like Firefox, emacs, ... But I have an issue on the copy and I don't know where the problem is. Assembly code : global strcpy section .text strcpy: push rbp …
0
votes
3 answers

How to use String in System() Command

i wanted to make a program for wget which asks you from which URL you want do download and then download, but i don't know how to add the string "wget" and the url and put it in the system() command. I know there are several possibilities to add…
Lorenz
  • 39
  • 6