473,659 Members | 2,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hi Can anyone help me out with this! thesis problem PLease :(

Hi, I m working on thesis on mechanical engieering. I m using C to
solve a particualr problem.
I have this code underneath which is giving me problems:
for (t=0;t<=maxt;t+ +){
printf("testing loop\n");
for (x=0;x<=maxx;x+ +){
for(y=0;y<=maxy ;y++){
printf(".");
if (x==0){
printf("hello") ;
tp[t][x][y]=tp[t-1][x+1][y]; //Problem here
}
}}}

I simplified as much as possible.

the problem is at the indicated line.

tp is a 3 dimensional array, allocated using calloc().

Im filling array with some values.

When the program arrives at this line, it exits and prints only one "."
and one "hello".

But without this line, it prints "." and "hello" according to the loop
iterations.

Can anhybody indetify the problem please ?

Im using Lcc win as a compiler and the array is a pointer to pointer to
pointer i.e. -- double ***tp

Thanks!!!

Alan

Nov 20 '06 #1
4 1306
Alan wrote:
Hi, I m working on thesis on mechanical engieering. I m using C to
solve a particualr problem.
I have this code underneath which is giving me problems:
for (t=0;t<=maxt;t+ +){
printf("testing loop\n");
for (x=0;x<=maxx;x+ +){
for(y=0;y<=maxy ;y++){
printf(".");
if (x==0){
printf("hello") ;
tp[t][x][y]=tp[t-1][x+1][y]; //Problem here
}
}}}

I simplified as much as possible.
When t == 0, tp[t-1]... is accessing an area of memory which is not a
part of the array. This is probably what's causing UB.

Nov 20 '06 #2
Alan wrote:
Hi, I m working on thesis on mechanical engieering. I m using C to
solve a particualr problem.
I have this code underneath which is giving me problems:
for (t=0;t<=maxt;t+ +){
printf("testing loop\n");
for (x=0;x<=maxx;x+ +){
for(y=0;y<=maxy ;y++){
printf(".");
if (x==0){
printf("hello") ;
tp[t][x][y]=tp[t-1][x+1][y]; //Problem here
}
}}}

I simplified as much as possible.

the problem is at the indicated line.

tp is a 3 dimensional array, allocated using calloc().

Im filling array with some values.

When the program arrives at this line, it exits and prints only one "."
and one "hello".

But without this line, it prints "." and "hello" according to the loop
iterations.
I'd make the "hello" line display t, x, and y. It might be
illuminating to see where/why this fails.

For example, what if x = 0 and t = 0? Looks like an out of bounds
access with tp[-1][1][y]... If maxx is also 0 the 1 is also out of
bounds.

Also, if you calloc standard doesn't guarantee that all bits 0 is a
valid float I believe, assign to 0.0 in a loop.

Also, if you calloc it this array as one big block, you can't use
multiple subscripts. See http://c-faq.com/aryptr/dynmuldimary.html.

-David

Nov 20 '06 #3


santosh wrote On 11/20/06 13:47,:
Alan wrote:
>>Hi, I m working on thesis on mechanical engieering. I m using C to
solve a particualr problem.
I have this code underneath which is giving me problems:
for (t=0;t<=maxt;t+ +){
printf("testing loop\n");
for (x=0;x<=maxx;x+ +){
for(y=0;y<=maxy ;y++){
printf(".");
if (x==0){
printf("hello") ;
tp[t][x][y]=tp[t-1][x+1][y]; //Problem here
}
}}}

I simplified as much as possible.


When t == 0, tp[t-1]... is accessing an area of memory which is not a
part of the array. This is probably what's causing UB.
Another potential trouble spot is the [x+1] index,
once the program gets up to x == maxx.

Yet another potential trouble spot is the use of <=
instead of < in the loop conditions. It might be all
right, but only if the array dimensions are a little
larger than might be expected. (For example, if maxt
is 5, the leftmost dimension requires at least 6 elements:
0,1,2,3,4,5 inclusive are six distinct index values.)

--
Er*********@sun .com

Nov 20 '06 #4
Alan wrote:
for (t=0;t<=maxt;t+ +){
printf("testing loop\n");
for (x=0;x<=maxx;x+ +){
for(y=0;y<=maxy ;y++){
printf(".");
if (x==0){
printf("hello") ;
tp[t][x][y]=tp[t-1][x+1][y]; //Problem here
}
}}}
In the first time through the loop t==0 so the assignment refers to
tp[-1][x+1][y], which is out of bounds.
Nov 20 '06 #5

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

Similar topics

0
1278
by: asdf sdf | last post by:
i have an install issue with moinmoin on win2k. i've tried the mailing list, but it appears to be a very low traffic, low subscriber list. can i get a reality check? is anyone using moinmoin in win2k? any issues? anyone at all?
1
2087
by: Simon Harvey | last post by:
Hi chaps, Does anyone know if the beast is going to release Visual Tools for office to work with Visual Studio 2002 and not just 2003, or are they quite happy to shaft those that supported them when their product just cam out. I can't see why the tools shouldnt work with 2002 seeing as its almost identical to 2003. Has anyone heard anything
1
1479
by: Greg Steele | last post by:
Does anyone have a copy or know where I can get an installation executable for chiliReports 2.0 from chili! soft? The company I'm working for bought a copy several years ago, then moved their datacenter and lost the installation in the process. I have the registration e-mail that was sent to them with the unlocking code so we just need the trial installation executable.
0
2272
by: james | last post by:
Hi guys! I´ve got a centerd table on my site with a black 1 pixel border. What i would like to do is to add a drop shadow to the table. Anyone know if it's possible to create a drop shadow for a table? Does anyone has an example? Thanks, James
162
7214
by: Isaac Grover | last post by:
Hi everyone, Just out of curiosity I recently pointed one of my hand-typed pages at the W3 Validator, and my hand-typed code was just ripped to shreds. Then I pointed some major sites (microsoft.com, cnn.com, etc.) at the W3 Validator; to my surprise none of them passed. Doesn't anyone care anymore, or are the standards more-or-less looked at as guidlines for web design?
13
2217
by: penguin732901 | last post by:
Checking back for discussions, there was a lot of talk about 2000 being slower than 97, but not so much lately. What is the latest opinion? Anyone care to set up a poll for how many NG members are still using 97? 2000? I am slightly tempted to upgrade by a new client whose data is in 2000, but of course, I can just port it all back through Excel...right? and I guess I have seen a couple of nice features...
3
1492
by: Jozef | last post by:
Hello, Has anyone here used the Visual Studio 2003 Office Developers Extensions? I'm wondering if the package and deployment wizard is any better than it's XP / 2002 counterpart. I already have 2002 Dev Edition, but would like something a little more configurable and a little more reliable when it comes to dependancies. Any input would be appreciated.
1
1091
by: Leveridge Systems INC | last post by:
We need help with ASP.net work in a Solomom env. Or know anyone ? .. we can reward in cash. -- John D Allen. CEO & President. Leveridge Systems INC.
0
1239
by: Joe Conway | last post by:
Does anyone out there have experience with commercial ETL tools and a Postgres based data warehouse (that they are at liberty to discuss)? Specifically I'd be interested in hearing if anyone is using Postgres as a source or target for Informatica or BusinessObjects Data Integrator. Thanks in advance. Joe
8
7408
by: firewood | last post by:
I am developing a form-based website development system using PHP5, and I want to incorporate a secure, reliable, Wysiwyg textarea script in place of the standard, unformatable, text-only textarea one gets with a <textarea> tag. All I need are basic formatting tools - bold, italics, underline, lists, tables. I've looked into a few already with spotty results: SPAW - is buggy with PHP5. Textarearich - is awkward to configure, and I'm...
0
8339
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,...
1
8535
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
8629
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
7360
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...
1
6181
isladogs
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...
0
5650
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
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
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 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.