#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)nu mpoints);
unsigned long int numpointsy = sqrt((double)nu mpoints);
numpoints = numpointsx * numpointsy;
unsigned long int i = 0;
typedef struct point
{
float x, y;
} point;
point *pointinarray;
pointinarray = calloc(sizeof(p oint), 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 1357
pereges wrote:
[...]
typedef struct point
{
float x, y;
} point;
point *pointinarray;
pointinarray = calloc(sizeof(p oint), 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)nu mpoints);
unsigned long int numpointsy = sqrt((double)nu mpoints);
numpoints = numpointsx * numpointsy;
unsigned long int i = 0;
typedef struct point
{
float x, y;
} point;
point *pointinarray;
pointinarray = calloc(sizeof(p oint), 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 runs fine if the user enters a number, but if the user enters a
letter it loops.
I have been working on this for 3 hours now, trying different things
|
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
statments as you can
|
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 program not lock up or quit right away when you enter a non
integer value. Now, even if you enter an integer value, it says to
enter an integer value. I hadf it set up so that the second time you
enter a non integer value, it quits. Now, the second...
|
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 statement).If either of the values is negative,the progra prints"Negative input" and terminates.Otherwie, it prints the values that the user enters.
After that, the program compares the first integer and the second ineger and prints either "The first integer...
|
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 statement).If eithere of the value is negative, the program prints "negative input" and terminates.Otherwise it prints the value the user entered.
After that,the program compares he first integer and the second integer and prints either, "the first...
| |
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 we set about doing that.
Every program starts with a specification, this may be a several hundred page document from your latest client or one small paragraph from your professor and pretty much anything in-between.
The specification is very...
|
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 the text files from the
watched folder line by line into variables and then posting them to a SQL
table.
All of the code for the form is shown below. And it works fine except for 2
issues.
First issue: In the Finally of the Try for teh SQL...
|
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 programatically either from UNIX or Oracle PLSQL. In this Section, I will be explaining about calling a Concurrent program from UNIX using the CONCSUB Command.
Pre-requisite:
1. Concurrent Program should be registered in oracle Applications...
|
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,...
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |