#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(void)
{
unsigned long int numpoints;
printf("Enter num of points\n");
scanf("%lu", &numpoints);
unsigned long int numpointsx = sqrt((double)numpoints);
unsigned long int numpointsy = sqrt((double)numpoints);
numpoints = numpointsx * numpointsy;
unsigned long int i = 0;
typedef struct point
{
float x, y;
} point;
point *pointinarray;
pointinarray = calloc(sizeof(point), numpoints);
float xlength, ylength;
xlength = ylength = 20;
float xmin, ymin;
xmin = ymin = -10;
float xmax, ymax;
xmax = ymax = 10;
float xsize = xlength /( numpointsx-1);
float ysize = ylength / (numpointsy-1);
printf("%u\n", numpoints);
unsigned long int xi, yi;
/* I'm confident the error is here */
for ( yi = 0; yi <= numpointsy; ++yi)
{
for (xi = 0; xi <= numpointsx; ++xi)
{
pointinarray[i].x = xmin + xi * xsize;
pointinarray[i].y = ymin + yi * ysize;
++i;
}
}
printf("i: %lu xmax: %f ymax: %f\n",i, pointinarray[i-1].x,
pointinarray[i-1].y);
return 0;
}
The program is working for anything upto 60000 or so but fails for
anything greater eg. 100000 2 1344
pereges wrote:
[...]
typedef struct point
{
float x, y;
} point;
point *pointinarray;
pointinarray = calloc(sizeof(point), numpoints);
[...]
The program is working for anything upto 60000 or so but fails for
anything greater eg. 100000
"Fails", how?
Pure speculation: the calloc(), for which you do not check for
failure, is failing on large values of "numpoints".
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
pereges wrote:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(void)
{
unsigned long int numpoints;
printf("Enter num of points\n");
scanf("%lu", &numpoints);
unsigned long int numpointsx = sqrt((double)numpoints);
unsigned long int numpointsy = sqrt((double)numpoints);
numpoints = numpointsx * numpointsy;
unsigned long int i = 0;
typedef struct point
{
float x, y;
} point;
point *pointinarray;
pointinarray = calloc(sizeof(point), numpoints);
float xlength, ylength;
xlength = ylength = 20;
float xmin, ymin;
xmin = ymin = -10;
float xmax, ymax;
xmax = ymax = 10;
float xsize = xlength /( numpointsx-1);
float ysize = ylength / (numpointsy-1);
printf("%u\n", numpoints);
You want the %lu conversion specifier here.
unsigned long int xi, yi;
/* I'm confident the error is here */
for ( yi = 0; yi <= numpointsy; ++yi)
{
for (xi = 0; xi <= numpointsx; ++xi)
{
pointinarray[i].x = xmin + xi * xsize;
pointinarray[i].y = ymin + yi * ysize;
++i;
}
}
printf("i: %lu xmax: %f ymax: %f\n",i, pointinarray[i-1].x,
pointinarray[i-1].y);
return 0;
}
The program is working for anything upto 60000 or so but fails for
anything greater eg. 100000
Why don't you put in a series of printf statements to print out the
values of your variables at selected points in the program. Then you
might be able to narrow down the point of failure. Alternatively you
could step through the program in a debugger. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Just starting out |
last post by:
I am very new to C code and I'm having a lot of trouble with a homework
assignment.
This program is supposed to take the amount of Euros that the user
enters and convert it to US dollars.
It...
|
by: jyck91 |
last post by:
please~help me to write a program to convert the baseN(2-9) to base10
eg. 101(2)----->5(10)
1211(3)------->X(10)
......
P.S. i am really misunderstand the C programming, plz write the simple...
|
by: bazymew |
last post by:
I'm new to C++(I've only started learning about a month ago), so
please don't call me stupid for asking a dumb question.
You see I was experimenting with Exception operators, trying to
make a...
|
by: haelly |
last post by:
Write a program that prompts the user to enter three different integer values.If the values are not different, the program prints a message"equal values" and terminates(hint: use the return...
|
by: haelly |
last post by:
write a program that prompts the user to enter three different positive integer values.If the values are not different, the program prints a message"equal value" and terminates(hint:use the return...
|
by: Banfa |
last post by:
Posted by Banfa
The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how...
|
by: Keith G Hicks |
last post by:
I'm having a lot of trouble with "file in use" errors in my "folder watcher"
project. Starting and stopping the watcher and reading my XML file work
fine. Once the watcher is started, I'm reading...
|
by: amitpatel66 |
last post by:
There is always a requirement that in Oracle Applications, the Concurrent Program need to be execute programatically based on certain conditions/validations:
Concurrent programs can be executed...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |