C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 23rd, 2013, 11:27 AM
ddeakpeti ddeakpeti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 ddeakpeti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 43 m 25 sec
Reputation Power: 0
What does the line stand for

Hi everyone. I have a programe and I'm trying to understand what's going on... in one of the lines.

the code is the following:
Code:
int main()
{
    srand((unsigned) time(0));

	double PI = 3.14159265358979323846;

    point points[N], randompoint;
    int i = 0; 
	int j;

    //generate N different points
    while (i < N) {
        randompoint.x = (double) (rand() % XLIM);
        randompoint.y = (double) (rand() % YLIM);
        int exist = 0;
        for (j = 0; j < i; ++j)
            if (points[j].x == randompoint.x && points[j].y == randompoint.y) {
                exist = 1;
                break;
            }
        if (!exist) {
            points[i].x = randompoint.x;
            points[i].y = randompoint.y;
            ++i;
        }
    } 


My question, is about the line: point points[N], randompoint;

What does it do? Or what kind of "thing" is it?
Maybe I should include the rest of the int main, let me know if this is not enough information.
Thanks in advance

Reply With Quote
  #2  
Old January 23rd, 2013, 11:47 AM
swapy swapy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Posts: 66 swapy Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 14 h 4 m
Reputation Power: 0
i think program is incomplete or u may have missed something..
point is a user defined datatype... it will be mostly a structure and its variables are x and y......

Reply With Quote
  #3  
Old January 23rd, 2013, 11:52 AM
swapy swapy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Posts: 66 swapy Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 14 h 4 m
Reputation Power: 0
what is xlim ylim... even some header file may be missing and N must have a value...

structure may look like this

struct p{
int x,y;
}point;

Reply With Quote
  #4  
Old January 23rd, 2013, 11:59 AM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 4,808 clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level)clifford User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Days 17 h 42 m 14 sec
Reputation Power: 1800
Code:
point points[N], randompoint;


Declares two variables, an array of points and a single point. It is the same as:

Code:
point points[N] ;
point randompoint ;


but is written by terminally lazy coders.

Reply With Quote
  #5  
Old January 23rd, 2013, 12:58 PM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,134 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 20 h 49 m 9 sec
Reputation Power: 1974
N, XLIM, and YLIM are undoubtedly macros created by #define statements; eg:
Code:
#define N 100
#define XLIM  42
#define YLIM  42

When you compile the program, first the pre-processor will scan through the source code and replace every occurance of a macro name with the string that it's defined as being; eg, assuming the example #define's above, this
Code:
    point points[N], randompoint;
    int i = 0; 
	int j;

    //generate N different points
    while (i < N) {
        randompoint.x = (double) (rand() % XLIM);
        randompoint.y = (double) (rand() % YLIM);

will become
Code:
    point points[100], randompoint;
    int i = 0; 
	int j;

    //generate N different points
    while (i < 100) {
        randompoint.x = (double) (rand() % 42);
        randompoint.y = (double) (rand() % 42);


Like the missing declaration of the struct point, those missing macro definitions are probably above main in the upper portion of the program that was not included.

BTW, it is common coding convention to write all macro names in all-caps, so that when reading the source code you can immediately recognize the macros. And since by this convention no other identifiers (variable, typedef, or function names) are written in all caps, that allows you to "reuse" those names. Therefore, while N is a macro, you can still use n as a variable name.
Comments on this post
swapy agrees!

Reply With Quote
  #6  
Old January 23rd, 2013, 01:23 PM
ddeakpeti ddeakpeti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 ddeakpeti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 43 m 25 sec
Reputation Power: 0
thank you for the clear and simple answer!

Reply With Quote
  #7  
Old January 23rd, 2013, 01:25 PM
ddeakpeti ddeakpeti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 ddeakpeti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 43 m 25 sec
Reputation Power: 0
Thank you for your response.
Yes, indeed, those macros are above ind the program.

Reply With Quote
  #8  
Old January 23rd, 2013, 01:53 PM
swapy swapy is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2010
Posts: 66 swapy Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 14 h 4 m
Reputation Power: 0
if i am not wrong point is a structure right?

sorry i got it

Last edited by swapy : January 23rd, 2013 at 02:02 PM.

Reply With Quote
  #9  
Old January 23rd, 2013, 02:11 PM
ddeakpeti ddeakpeti is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 14 ddeakpeti User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 43 m 25 sec
Reputation Power: 0
Yes, it is. It's my mistake. Sorry

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > What does the line stand for

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap