comp.lang.c
[Top] [All Lists]

Re: K&R2 , exercise 7.6

Subject: Re: K&R2 , exercise 7.6
From: arnuld
Date: Thu, 01 May 2008 03:02:20 +0500
Newsgroups: comp.lang.c

> On Tue, 29 Apr 2008 18:34:16 -0700, Barry Schwarz wrote:

>> On Tue, 29 Apr 2008 15:47:30 +0500, arnuld <NoSpam@xxxxxxxxxx> wrote:

>>  char *buffer  = 0;
>>  char *buffer2 = NULL;
>>
>>    printf("%s\n%s\n", buffer, buffer2);
 
> Obviously you wanted to do something else rather than invoke undefined
> behavior here.  Did you mean to use %p instead of %s?  If so, it would
> be a good to acquire the habit of casting the pointers to void* (even
> though a char* would work without the cast).

I really meant %s because I am providing printf an array, whether empty or
full and you do see that its prints without any problem:

 
/home/arnuld/programs/C $ gcc -ansi -pedantic -Wall -Wextra test.c 
/home/arnuld/programs/C $ ./a.out 
(null)
(null)
/home/arnuld/programs/C $ 

 

BTW, I used %d, %lu, %s but what is %p ?


-- 
http://lispmachine.wordpress.com/
my email ID is at the above address


<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy