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:
- Copy the character in
*sourceto*destination - If the character that was just copied was the null terminator, exit.
- Otherwise, increment the pointer to
source, and increment the pointer todestination. - Go to step 1.
Programiz
programiz.com › c-programming › examples › string-copy
C Program to Copy String Without Using strcpy()
As you know, the best way to copy a string is by using the strcpy() function.
Log2Base2
log2base2.com › c-examples › string › string-copy.html
C program to copy string without using strcpy() function
'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
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 · Solution: Explanation: Tags · C Examples · C Easy Examples ·
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
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
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.
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];
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; }
CodeScracker
codescracker.com › c › program › c-program-copy-string.htm
C Program to Copy One String to Another
As you can see from the above snapshot, only "codes" are initialized in the variable str1, and the value of str1 gets copied to the str2 variable. Therefore, the above program is correct only when the user doesn't supply any strings with spaces. This program performs the same function as the previous one, but without the use of the library function strcpy():
Naukri
naukri.com › code360 › library › c-program-to-copy-first-string-into-second-string
C Program to copy first string into second string
March 27, 2024 - Almost there... just a few more seconds
PREP INSTA
prepinsta.com › home › all about c language › program for string copy in c
String Copy in C | PrepInsta
January 31, 2023 - In the program, we will require some numbers from the user or pre-defined variables depending on the program requirement to copy the string into another string. ... Step 2: Declare the variable str1 and str2. Step 3: Read input str1 from the user or predefine it according to the need. Step 4: Use the syntax to copy the string into the empty string. Step 5: Print the result of the program compiled. Step 6: Program end. Write a program to copy string without using strcpy().
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.