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

G

gdotone

#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.
 
G

gdotone

#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.
 
B

Barry Schwarz

#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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top