Thread: strcpy

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    230

    strcpy

    i was reading the tutorials on this website and got to strcpy. this is what it says(with my concern underlined)
    strcpy is short for string copy, which means it copies the entire contents of src into dest. The contents of dest after strcpy will be exactly the same as src such that strcmp ( dest, src ) will return 0.
    what i understand from this is that strcpy will return 0. well i tried it out with printf and it gave me <dest>. am i understanding the tutorial wrong? or do i understand the term "return" wrong? doesn't 5 * 6 return 30(as an example)? heres my src anyway
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main() {
       int i;
       char string1[256], string2[256];
       
       printf("Enter first string: ");
       fgets(string1, 256, stdin);
       printf("Enter second string: ");
       fgets(string2, 256, stdin);
       for(i = 0; i < 256; i++) {
          if(string1[i] == '\n') string1[i] = '\0';
          if(string2[i] == '\n') string2[i] = '\0';
       }
       printf("%s", strcpy(string1, string2));
       getchar();
       return 0;
    }
    Last edited by Abda92; 09-13-2006 at 05:18 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Full Program to analyze.
    By sergioms in forum C Programming
    Replies: 2
    Last Post: 12-30-2008, 09:42 AM
  2. Strcpy
    By Godders_2k in forum C Programming
    Replies: 17
    Last Post: 12-12-2007, 12:34 PM
  3. Where is strcpy() defined? (Can't find in string.h ect)
    By Zero_Point in forum C++ Programming
    Replies: 6
    Last Post: 04-03-2006, 05:14 PM
  4. Question about strcpy
    By Kevinmun in forum C Programming
    Replies: 4
    Last Post: 11-02-2005, 11:00 PM
  5. strcpy
    By Luigi in forum C++ Programming
    Replies: 17
    Last Post: 02-16-2003, 04:11 PM