473,803 Members | 3,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

printing values of "arrays of pointers"

PURPOSE: see the comments.
WHAT I GOT: infinite loop

/* This program will simply create an array of pointers to integers
* and will fill it with some values while using malloc to create
* pointers to fill the array and then will print the values pointed
* by those pointers
*
*/

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

enum MAXSIZE { ARRSIZE = 100 };
int main( void )
{
int* arr_p[ARRSIZE];
int** pp;
int *mp, *np;
int i;

int null_int = 0;

pp = arr_p;
np = &null_int;
for( i = 0; i < ARRSIZE - 1; ++i )
{
mp = malloc( sizeof( int ) );
mp = &i;
arr_p[i] = mp;
}
arr_p[i] = np;

while( **pp )
{
printf("**pp = %d\n", **pp);
}

return 0;
}

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

Jun 27 '08
24 2196
On Sat, 03 May 2008 16:21:35 +0530, santosh wrote:

More practically Sunsite could terminate his account with them if they
were to be alerted to his behaviour. Their rules clearly say that users
are only to use their own email addresses which actually exist and can
be delivered to, in the Sender field.

If I use my real email ID that means I am inviting 100% of spam. I don't
want to be spammed and no one wants to be spammed.

Regarding microsoft.com, I got that idea from my friend. He told me that
when he is using Outlook Express on WindowsXP, he gets this:
....@microsoft. com, as default address.

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

Jun 27 '08 #11
On Sat, 03 May 2008 16:21:35 +0530, santosh wrote:

More practically Sunsite could terminate his account with them if they
were to be alerted to his behaviour. Their rules clearly say that users
are only to use their own email addresses which actually exist and can
be delivered to, in the Sender field.

I think this Server Policy is good:

http://news.aioe.org/spip.php?article3

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

Jun 27 '08 #12
On Sat, 03 May 2008 16:21:35 +0530, santosh wrote:

More practically Sunsite could terminate his account with them if they
were to be alerted to his behaviour. Their rules clearly say that users
are only to use their own email addresses which actually exist and can
be delivered to, in the Sender field.

I have mailed them and have asked them to change their policy.

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

Jun 27 '08 #13
arnuld said:
>On Sat, 03 May 2008 16:21:35 +0530, santosh wrote:

>More practically Sunsite could terminate his account with them if they
were to be alerted to his behaviour. Their rules clearly say that users
are only to use their own email addresses which actually exist and can
be delivered to, in the Sender field.


If I use my real email ID that means I am inviting 100% of spam. I don't
want to be spammed and no one wants to be spammed.
Nobody wants to be spammed. On the other hand, how would you like it if
someone used *your* real address in *their* From field?

All you have to do is invent an address that is in the correct form but
guaranteed not to exist. For example, sp**@spam.invalid is a well-formed
email address that definitely doesn't exist (because there is no top-level
domain called "invalid"). This is not an area where originality is
terribly important. If in doubt, use sp**@spam.invalid for From and
Reply-To, and mung your real email address in your sig block.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #14
On Mon, 05 May 2008 04:48:11 +0000, Richard Heathfield wrote:
Nobody wants to be spammed. On the other hand, how would you like it if
someone used *your* real address in *their* From field?
:(

All you have to do is invent an address that is in the correct form but
guaranteed not to exist. For example, sp**@spam.invalid is a well-formed
email address that definitely doesn't exist (because there is no top-level
domain called "invalid"). This is not an area where originality is
terribly important. If in doubt, use sp**@spam.invalid for From and
Reply-To, and mung your real email address in your sig block.

how about my present address ? It doe not use any real domain name and is
different enough from common words like spam, invalid, nospam etc.

BTW, I don't see Reply-To header for my own posts, not even for the posts
of BartC and santosh but I do see Reply-To header of yours. ( I have
already enabled all headers in PAN preferences)

--
http://lispmachine.wordpress.com/
my email ID is @ the above blog.
just check the "About Myself" page :)

Jun 27 '08 #15
arnuld wrote:
>Richard Heathfield wrote:
.... snip ...
>
>All you have to do is invent an address that is in the correct
form but guaranteed not to exist. For example, sp**@spam.invalid
is a well-formed email address that definitely doesn't exist
(because there is no top-level domain called "invalid"). This is
not an area where originality is terribly important. If in doubt,
use sp**@spam.invalid for From and Reply-To, and mung your real
email address in your sig block.

how about my present address ? It doe not use any real domain
name and is different enough from common words like spam, invalid,
nospam etc.
No. People can create new domains and addresses at any time. The
..invalid domain is guaranteed not to exist, and thus to never cause
problems.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #16
On Mon, 05 May 2008 02:25:53 -0400, CBFalconer wrote:
No. People can create new domains and addresses at any time. The
.invalid domain is guaranteed not to exist, and thus to never cause
problems.

so "invalid" is the only one that is usable :(

--
http://lispmachine.wordpress.com/
my email ID is @ the above blog.
just check the "About Myself" page :)

Jun 27 '08 #17
arnuld <su*****@domain .tldwrites:
>On Mon, 05 May 2008 02:25:53 -0400, CBFalconer wrote:
No. People can create new domains and addresses at any time. The
.invalid domain is guaranteed not to exist, and thus to never cause
problems.

so "invalid" is the only one that is usable :(
<OT>
No, it's not the only one, but it's the most appropriate for your
purposes. Point your web browser to <http://example.com/and follow
the link for more information.

But even if it were the only one, why would that be a problem? How
many invalid TLDs do you need? (Hint: the correct answer is an
integer between 0 and 2.)

If you want to discuss this further, please find a newsgroup or other
forum where it's topical.
</OT>

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #18
On 2 May, 14:44, Richard Heathfield <r...@see.sig.i nvalidwrote:
arnuld said:
PURPOSE: * * * * see the comments.
WHAT I GOT: * * *infinite loop
/* This program will simply create an array of pointers to integers
** and will fill it with some values while using malloc to create
** pointers to fill the array and then will print the values pointed
** by those pointers
**
**/
#include <stdio.h>
#include <stdlib.h>
enum MAXSIZE { ARRSIZE = 100 };
int main( void )
{
* int* arr_p[ARRSIZE];
* int** pp;
* int *mp, *np;
* int i;
* int null_int = 0;
* pp = arr_p;
* np = &null_int;
* for( i = 0; i < ARRSIZE - 1; ++i )
* * {
* * * mp = malloc( sizeof( int ) );

You don't check to see whether this fails to allocate the requested
memory...
* * * mp = &i;

...which doesn't really matter, since you throw it away here.
* * * arr_p[i] = mp;
* * }

Well done. You just filled arr_p with a bunch of pointers to i. Why
bother with the malloc call, then? You could save yourself
(ARRSIZE-1) * sizeof(int) bytes of memory leak by removing the malloc call completely.
* arr_p[i] = np;
* while( **pp )

pp has the value &arr_p[0], so **pp attempts to find the int value at
*arr_p[0]. Since arr_p[0] points to i, we're looking for the value of i.
That value is indeterminate, because the object i never had a value
assigned to it.
not even in the for loop?

Thus, the behaviour is undefined. This loop could execute
forever (the most likely possibility) or not at all (probably the
second most likely) or something completely weird could happen.
* * {
* * * printf("**pp = %d\n", **pp);
if you want to print a pointer (and **pp *isn't a pointer)
use %p. Instead of trying to be clever why not use a for loop?

for (i = 0; i < ARRSIZE; i++)
printf ("%p ", (void*)arr_p[i]);

printf ("\n");

* * }

You don't even /try/ to iterate through the array, do you? You might
want
to take a long hard look at Visual Basic or RCX.

--
Nick Keighley

My god it's full of stars!
Dave Bowman, on seeing HAL's source code
Jun 27 '08 #19
On 2 May, 15:05, arnuld <NoS...@microso ft.comwrote:
On Fri, 02 May 2008 13:44:50 +0000, Richard Heathfield wrote:
* for( i = 0; i < ARRSIZE - 1; ++i )
* * {
* * * mp = malloc( sizeof( int ) );
You don't check to see whether this fails to allocate the requested
memory...

done
* * * mp = &i;
...which doesn't really matter, since you throw it away here.

well, then how can I generate a new variable every-time I enter into
the loop ?
you can't. Well you can but you don't want to.

for( i = 0; i < ARRSIZE - 1; ++i )
{
int new;
arr_p[i] = &new;
}

The Standard doesn't say if new has the same address every time,
but on almost any reasonable implementation it does. Hence you
don't want to do this.

So why not malloc an object and store its address in the array?
You probably meant to do that but your code really didn't
do that.

for( i = 0; i < ARRSIZE - 1; ++i )
{
if ((mp = malloc (sizeof (int))) == NULL)
{
fprintf (stderr, "memory error\n");
abort();
}

arr_p[i] = mp;
}
<snip>

--
Nick Keighley

-pedantic
This option is not intended to be useful; it exists only to satisfy
pedants who would otherwise claim that GNU CC fails to support the
ANSI standard.
(Using and Porting GNU CC)
Jun 27 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
11215
by: Abdullah Kauchali | last post by:
Hi folks, Can one rely on the order of keys inserted into an associative Javascript array? For example: var o = new Object(); o = "Adam"; o = "Eve";
388
21948
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's worth the $25USD. I'm just looking for a book on Pointers, because from what I've read it's one of the toughest topics to understand. thanks in advanced.
46
2274
by: TTroy | last post by:
Hi, I'm just wondering why people/books/experts say "the function returns a pointer to.." or "we have to send scanf a pointer to.." instead of "the function returns the address of.." or "we have to send scanf the address of.." Isn't the lvalue called a POINTER TO and the (r)value called the ADDRESS OF?
2
3227
by: Alfonso Morra | last post by:
Hi, I want to create a container structure (array/list etc), that is expandable. Currently, I have static arrays like this SomeStruct *ptrArray ; What I want to do is to be able to use ptrs to ptrs like so:
14
2840
by: Alf P. Steinbach | last post by:
Not yet perfect, but: http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01.pdf http://home.no.net/dubjai/win32cpptut/special/pointers/ch_01_examples.zip To access the table of contents, use the "Bookmarks" tab in Adobe Acrobat. Comments, corrections, praise, nits, etc., are still welcome!
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.