You are merely copying the starting address of str to temp. This means that any changes to temp will be reflected in str as well, since they point to the same memory. It does not truly emulate strcpy(dest, src), which creates a separate copy of the null-terminated string pointed to by src starting at the memory location pointed to by dest.

So, to answer your question as asked: no.

If your intent is to avoid the O(n) running time of strcpy, that's also something you can't really do.

If you're required by a programming assignment or exercise to create code functionally equivalent to strcpy, here is a high-level description of the algorithm it uses:

  1. Copy the character in *source to *destination
  2. If the character that was just copied was the null terminator, exit.
  3. Otherwise, increment the pointer to source, and increment the pointer to destination.
  4. Go to step 1.
Answer from Govind Parmar on Stack Overflow
🌐
Programiz
programiz.com › c-programming › examples › string-copy
C Program to Copy String Without Using strcpy()
In this C programming example, you will learn to copy strings without using the strcpy() function.
🌐
Tutorial Gateway
tutorialgateway.org › c-program-to-copy-string
C program to Copy String without using strcpy
April 4, 2025 - We can achieve the same in multiple ways, but we will discuss four different approaches: using For Loop, While Loop, Functions, and Pointers. This program for string copy allows the user to enter any character array.
🌐
Onlinegdb
learn.onlinegdb.com › c_program_copy_string_without_using_strcpy
C Program to copy string without using strcpy() | Learn Programming step by step
Problem Statement: Write a C Program to copy string without using strcpy() · Required Knowledge: C Input/Output, C Variables, C Datatypes, C for..loop
🌐
Log2Base2
log2base2.com › c-examples › string › string-copy.html
C program to copy string without using strcpy() function
#include<stdio.h> int main() { char str[100],copy_str[100]; int i; scanf("%s",str); /* * Let's assume string as "abc" */ for(i = 0; str[i] != '\0'; i++) copy_str[i] = str[i]; /* * i = 0; copy_str[0] = str[0] i.e. 'a' * i = 1; copy_str[1] = str[1] i.e. 'b' * i = 2; copy_str[2] = str[2] i.e. 'c' * i = 3; str[i] == '\0'. It will come out of loop */ copy_str[i] = '\0'; // i = 3; copy_str[3] = '\0'; printf("Copied string = %s",copy_str); return 0; } Run it
🌐
Vultr
docs.vultr.com › clang › examples › copy-string-without-using-strcpy
C Program to Copy String Without Using strcpy() | Vultr Docs
December 4, 2024 - This code snippet copies the string from source to destination using array indexing. Characters are copied one by one until the null character '\0' is encountered, indicating the end of the string.
🌐
TutorialsPoint
tutorialspoint.com › c-program-to-copy-string-without-using-strcpy-function
C program to copy string without using strcpy() function
#include<stdio.h> main() { char str[50]; //create an empty string to store another string char *myString = "Program to copy a String"; sprintf(str, "%s", myString);//Use sprintf to copy string from myString to str printf("The String is: %s", str); }
🌐
YouTube
youtube.com › watch
50 - STRING COPY WITHOUT USING STRCPY FUNCTION - C PROGRAMMING - YouTube
This program is for copying the content of one string to another string without using string handling function (strcpy( ))
Published   October 30, 2017
Find elsewhere
🌐
YouTube
youtube.com › techaeron
How to copy string without using strcpy() function C programming|| C language tutorial for beginners - YouTube
In this C programming tutorial, we're going to learn how to copy one string into another string without using strcpy() function. strcpy() function is a built...
Published   September 3, 2022
Views   759
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › different-ways-to-copy-a-string-in-c-c
Different ways to copy a string in C/C++ - GeeksforGeeks
July 23, 2025 - memcpy() is hardware optimized and copies faster and works with any type of source data (like binary or encrypted bytes). strcpy() should never be used unless for any specific reason, and if you know the lengths of the strings, memcpy() is a ...
🌐
IncludeHelp
includehelp.com › c-programs › c-program-to-copy-string-string-copy-strcpy.aspx
C program to copy one string into another | Implementing strcpy() in C
C program to copy one string to another (implementation of strcpy). Copy one string to another, string copy without using strcpy or library function.
🌐
Codeforwin
codeforwin.org › home › c program to copy one string to another string
C program to copy one string to another string - Codeforwin
July 20, 2025 - /** * C program to copy one string to another string without using strcpy() */ #include <stdio.h> #define MAX_SIZE 100 // Maximum size of the string int main() { char text1[MAX_SIZE]; char text2[MAX_SIZE]; int i; /* Input string from user */ printf("Enter any string: "); gets(text1); /* Copy text1 to text2 character by character */ for(i=0; text1[i]!='\0'; i++) { text2[i] = text1[i]; } //Makes sure that the string is NULL terminated text2[i] = '\0'; printf("First string = %s\n", text1); printf("Second string = %s\n", text2); printf("Total characters copied = %d\n", i); return 0; }
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 61417-copy-string-without-using-strcpy.html
Copy String without using strcpy
Well, gee, it's sure a good thing you did that, because none of us knew how. I mean, the only reason we didn't just post full working code is because we couldn't figure it out. Oh, and your code is wrong. The second string won't have a null terminator, and when you try and use it, you'll merrily run off the end of your array.
🌐
Programming Simplified
programmingsimplified.com › c › source-code › c-program-copy-strings
String copy in C | Programming Simplified
C program to copy a string using library function strcpy and without using strcpy · int main() { char source[1000], destination[1000];
🌐
Eazynotes
eazynotes.com › notes › c › programs › program-to-copy-one-string-to-another-without-using-strcpy.pdf pdf
Program to Copy one String to Another Without Using strcpy()
EazyNotes is a place where a student pursuing computer education would like to visit. Here, a student can find easy notes of various computer subjects.
🌐
Stack Overflow
stackoverflow.com › questions › 74259667 › swapping-and-copying-two-strings-into-one-another-without-using-strcpy-in-c
while loop - Swapping and copying two strings into one another without using strcpy() in C - Stack Overflow
this program is meant to take two strings and call a function that copies string 1 into string2, and vice versa, while fulfilling the following criteria: Uses pointers Uses only while loops does n...
🌐
Techcrashcourse
techcrashcourse.com › 2016 › 04 › cpp-program-to-copy-string-without-strcpy.html
C++ Program to Copy String Without Using strcpy
C++ program to copy string without using strcpy function with algorithm and sample input and output. How to copy string using while loop.