strcpy(s, "ABC"); gives a warning why...

Discussion in 'C Programming' started by gdotone@gmail.com, Jul 25, 2012.

  1. Guest

    #include <stdio.h>
    #include <stdlib.h>

    #define MAXSTRING 100


    int main(int argc, const char * argv[])
    {

    char c = 'a', *p, s[MAXSTRING];

    p = &c;
    printf ("%c%c%c \n", *p, *p + 1, *p + 2);

    strcpy(s, "ABC");
    printf ( "%s %c%c%s\n", s, *s + 6, *s + 7, s + 1 );

    strcpy(s, "she sells sea shells by the seashore" );
    p = s + 14;

    for ( ; *p != '\0'; ++p )
    {
    if ( *p == 'e' )
    *p = 'E';

    if ( *p == ' ' )
    *p = '\n';
    }

    printf ( "%s\n\n", s );

    return 0;
    }

    This program come from "A Book on C"
    When I compile this program I get a warning from the compiler.

    Implicitly declaring C library function 'strcpy' with type 'char*(char *, const char *)'

    The compiler is LLVM 3.1

    Why am I getting this warning? What does it mean? How can it be fixed so that there is no warning given?

    Thanks, everyone.
     
    , Jul 25, 2012
    #1
    1. Advertising

  2. Ike Naar Guest

    On 2012-07-25, <> wrote:
    > Implicitly declaring C library function 'strcpy' with type 'char*(char *, const char *)'


    #include <string.h>
     
    Ike Naar, Jul 25, 2012
    #2
    1. Advertising

  3. Guest

    On Wednesday, July 25, 2012 3:43:05 AM UTC-4, wrote:
    > #include &lt;stdio.h&gt;
    > #include &lt;stdlib.h&gt;
    >
    > #define MAXSTRING 100
    >
    >
    > int main(int argc, const char * argv[])
    > {
    >
    > char c = 'a', *p, s[MAXSTRING];
    >
    > p = &amp;c;
    > printf (&quot;%c%c%c \n&quot;, *p, *p + 1, *p + 2);
    >
    > strcpy(s, &quot;ABC&quot;);
    > printf ( &quot;%s %c%c%s\n&quot;, s, *s + 6, *s + 7, s + 1 );
    >
    > strcpy(s, &quot;she sells sea shells by the seashore&quot; );
    > p = s + 14;
    >
    > for ( ; *p != '\0'; ++p )
    > {
    > if ( *p == 'e' )
    > *p = 'E';
    >
    > if ( *p == ' ' )
    > *p = '\n';
    > }
    >
    > printf ( &quot;%s\n\n&quot;, s );
    >
    > return 0;
    > }
    >
    > This program come from &quot;A Book on C&quot;
    > When I compile this program I get a warning from the compiler.
    >
    > Implicitly declaring C library function 'strcpy' with type 'char*(char *, const char *)'
    >
    > The compiler is LLVM 3.1
    >
    > Why am I getting this warning? What does it mean? How can it be fixed so that there is no warning given?
    >
    > Thanks, everyone.
     
    , Jul 25, 2012
    #3
  4. Guest

    Thanks.
     
    , Jul 25, 2012
    #4
  5. On Wednesday, July 25, 2012 2:43:05 AM UTC-5, wrote:
    > #include &lt;stdio.h&gt;
    > #include &lt;stdlib.h&gt;
    >
    > #define MAXSTRING 100
    >
    >
    > int main(int argc, const char * argv[])
    > {
    >
    > char c = 'a', *p, s[MAXSTRING];
    >
    > p = &amp;c;
    > printf (&quot;%c%c%c \n&quot;, *p, *p + 1, *p + 2);
    >
    > strcpy(s, &quot;ABC&quot;);
    > printf ( &quot;%s %c%c%s\n&quot;, s, *s + 6, *s + 7, s + 1 );
    >
    > strcpy(s, &quot;she sells sea shells by the seashore&quot; );
    > p = s + 14;
    >
    > for ( ; *p != '\0'; ++p )
    > {
    > if ( *p == 'e' )
    > *p = 'E';
    >
    > if ( *p == ' ' )
    > *p = '\n';
    > }
    >
    > printf ( &quot;%s\n\n&quot;, s );
    >
    > return 0;
    > }
    >
    > This program come from &quot;A Book on C&quot;
    > When I compile this program I get a warning from the compiler.
    >
    > Implicitly declaring C library function 'strcpy' with type 'char*(char *, const char *)'
    >
    > The compiler is LLVM 3.1
    >
    > Why am I getting this warning? What does it mean? How can it be fixed so that there is no warning given?
    >
    > Thanks, everyone.


    You should be aware that the standard does not guarantee that 'a'+1, 'a'+2,'A'+6, or 'A'+7 represent printable characters. It is not a problen in the two common character sets (ASCII and EBCDIC). But in EBCDIC, 'A'+9 is not printable while it is in ASCII.
     
    Barry Schwarz, Jul 26, 2012
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jiong Feng
    Replies:
    0
    Views:
    905
    Jiong Feng
    Nov 19, 2003
  2. Bruce Sam
    Replies:
    15
    Views:
    8,034
    John C. Bollinger
    Nov 19, 2004
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,129
    Smokey Grindel
    Dec 2, 2006
  4. vsgdp

    ABC inheriting from ABC

    vsgdp, Sep 24, 2005, in forum: C++
    Replies:
    1
    Views:
    323
    vsgdp
    Sep 24, 2005
  5. Gunter Henriksen

    x.abc vs x['abc']

    Gunter Henriksen, May 13, 2009, in forum: Python
    Replies:
    1
    Views:
    370
    alex23
    May 15, 2009
Loading...

Share This Page