473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Strange loop

Hello!

I wrote short program:

#include <stdio.h>

main(){
int Uporzadkowana[255][255];
int Tablica[64*1024];
Tablica[0]=1;
for(int i = 0; i < 256; i++){
for(int j = 0; j < 256; j++){
printf("i=%i, j=%i...",i,j);
}
}
printf("%i",Tablica[0]);
}

And "i" and "j" both grow up, but when I've add this line:

Uporzadkowana[j][i]=Tablica[0];

into loop, under printf, "i" is always "0", why??? I'm using CBuilder5.
---
Chris


Jul 19 '05 #1
2 1801
Krzysztof Kolago wrote:

I wrote short program:

#include <stdio.h>

main(){
int Uporzadkowana[255][255];
int Tablica[64*1024];
Tablica[0]=1;
for(int i = 0; i < 256; i++){
for(int j = 0; j < 256; j++){
printf("i=%i, j=%i...",i,j);
}
}
printf("%i",Tablica[0]);
}

And "i" and "j" both grow up, but when I've add this line:

Uporzadkowana[j][i]=Tablica[0];

into loop, under printf, "i" is always "0", why???


Hello Chris,

I rewrote your code slightly so that it complies with the C++ standard:

#include <cstdio>
using std::printf;

int main() {
int Uporzadkowana[255][255];
int Tablica[64*1024];
Tablica[0]=1;
for(int i = 0; i < 255; i++){
for(int j = 0; j < 255; j++){
printf("i=%i, j=%i...",i,j);
Uporzadkowana[j][i]=Tablica[0];
}
}
printf("%i",Tablica[0]);
}

Also note that I changed the loop conditions to "i < 255" and "j < 255."
Each dimension of the two-dimensional array is 255 elements, indexed from 0
to 254. 255 is not a valid index.

What happens when you compile and run my version of your program? When I
run it, I get the output you would expect. i is not always 0; it changes
incrementally from 0 to 254.

--
Russell Hanneken
rg********@pobox.com
Remove the 'g' from my address to send me mail.
Jul 19 '05 #2
Krzysztof Kolago wrote:
Hello!

I wrote short program:

#include <stdio.h>

main(){
int Uporzadkowana[255][255];
int Tablica[64*1024];
Tablica[0]=1;
for(int i = 0; i < 256; i++){ This iterates 256 times, yet your array is only 255 elements.

I'm not sure this is your problem but it's certainly an issue.
for(int j = 0; j < 256; j++){
printf("i=%i, j=%i...",i,j);
}
}
printf("%i",Tablica[0]);
}

And "i" and "j" both grow up, but when I've add this line:

Uporzadkowana[j][i]=Tablica[0];

into loop, under printf, "i" is always "0", why??? I'm using CBuilder5.

Jul 19 '05 #3

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

Similar topics

4
by: hall | last post by:
Hi. I've come across someting strange. I was trying to make a for-loop execute repetadly until the function called inside it does not return true during the entire loop (see program below). ...
1
by: Narya | last post by:
Hello guys, I got a strange problem when using for loop. For example, the following code for ($j = 0.0; $j <= 2; $j+=0.2) { print $j, " "; } gives 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6...
2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
2
by: TB | last post by:
I am seeing a very strange problem as follows... I have a loop where a fair amount of processing is going on and near the top of the loop I access a class that has only static helper functions...
5
by: cody | last post by:
I have a very funny/strange effect here. if I let the delegate do "return prop.GetGetMethod().Invoke(info.AudioHeader, null);" then I get wrong results, that is, a wrong method is called and I...
20
by: SpreadTooThin | last post by:
I have a list and I need to do a custom sort on it... for example: a = #Although not necessarily in order def cmp(i,j): #to be defined in this thread. a.sort(cmp) print a
4
by: | last post by:
Im getting that error (It is strange. I Run my programme step by step pressing f11. im looping SqlCommand in a while loop. The First step runs but when a enter 2nd step in my loop it returns error...
11
by: VijaKhara | last post by:
Hi all, I just write a very simple codes in C and vthere is a very strange bug which I cannot figure out why. The first loop is for v, and the second for k. There is no relationship between v...
3
by: Rinaldo | last post by:
Hi, I have a label on my dialogbox who has to change text while running. This is what I do: lblBackup.Text = "Bezig met de backup naar " + F1.FTPserver; but the text does'nt appear, only if...
6
by: markus.litz | last post by:
Hello, I have a strange problem with some of my c++ code. I have a normal for- loop like this for(int i = 1; ..... on MS-Windows with a Microsoft compiler everything is alright, but when I...
0
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
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
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...
0
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...
0
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,...
0
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...

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.