April 15, 2021, 03:24:43 AM

Author Topic: Basic C++ Programming Help  (Read 22769 times)

0 Members and 1 Guest are viewing this topic.

ajastru2000

  • Guest
Re:Basic C++ Programming Help
« Reply #15 on: July 08, 2003, 10:34:33 PM »
sorry guyz....was down with SARS :-[ .......actually flu....stil hvnt got time 2 solve my problem.....btw rgding dis WMD....i hv given al details on it 2 d UN..... ;D

Offline wilnix

  • mv user /dev/null
  • Administrator
  • Forum Hero
  • *****
  • Posts: 690
  • Country:
  • Gender: Male
  • You're not the fastest packet in the subnet...
    • Wilnix - The NetAdmin's Resource
Re:Basic C++ Programming Help
« Reply #16 on: July 09, 2003, 01:46:23 AM »
s/gov/com   ???


wilnix
« Last Edit: July 09, 2003, 01:46:32 AM by wilnix »
alt email address: wilnix@hackphreak.org

Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Basic C++ Programming Help
« Reply #17 on: July 09, 2003, 02:41:21 PM »
hehe,

that's cool.. hope you solve the problem when you're well. If not, feel free to ask more.

Met.
"My Terminal is my Soul"

Offline wilnix

  • mv user /dev/null
  • Administrator
  • Forum Hero
  • *****
  • Posts: 690
  • Country:
  • Gender: Male
  • You're not the fastest packet in the subnet...
    • Wilnix - The NetAdmin's Resource
Re:Basic C++ Programming Help
« Reply #18 on: July 10, 2003, 08:04:38 PM »
Go back to using cobol...it makes you crazy!!

 :P wilnix
alt email address: wilnix@hackphreak.org

ajastru2000

  • Guest
Re:Basic C++ Programming Help
« Reply #19 on: July 14, 2003, 07:55:58 AM »
#define MAX 5
int main(void)
{
int i, j, array1[5], array2[5];

array1[0] = '1';
array1[1] = '0';
array1[2] = '0';
array1[3] = '7';

array2[0] = '1';
array2[1] = '5';
array2[2] = '0';
array2[3] = '2';


for (i=0;i<MAX-1;i++) {
  for(j=0;j<MAX-1;j++) {
      if (array1 == array2[j]) {
        printf("we found a match at array1 element %d and array2 element %d \n", i, j);

          }
        }
    }

return 0;

}


Guyz...srry just recovered frm d flu bout was bad. I tried to put in more loops and variables to get:

1)the program to search once only for element 1(array1) with the first 3 rows of element(array2).

2)If match is found for element1(array1) proceed to element 2(array1) and search for the consequent 3 rows after the matched element 'n'(array2).

3)If a match is not found for element 1(array1) proceed to element 2(array1) and search for the next consequent 3 rows
of element after element 1(array2).

and only show the matched value like the result before. Srry to trouble u guyz but i cant solve it still.Thanx again for both ur patience.






Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Basic C++ Programming Help
« Reply #20 on: July 14, 2003, 04:02:50 PM »
Okay, first, I see the code did not get entered correctly. so let me try again:

Code: C++
  1.  
  2. #define MAX 5
  3. int main(void)
  4. {
  5. int i, j, array1[5], array2[5];
  6.  
  7. array1[0] = '1';
  8. array1[1] = '0';
  9. array1[2] = '0';
  10. array1[3] = '7';
  11.  
  12.  
  13. array2[0] = '1';
  14. array2[1] = '5';
  15. array2[2] = '0';
  16. array2[3] = '2';
  17.  
  18.  
  19. for (i=0;i<MAX-1;i++) {
  20.   for(j=0;j<MAX-1;j++) {
  21.       if (array1[i] == array2[j]) {
  22.         printf("we found a match at array1 element %d and array2 element %d \n", i, j);
  23.  
  24.           }
  25.         }
  26.     }
  27.  
  28. return 0;
  29.  
  30. }
  31.  

Now, you should know that if you want the array bigger, you can change the MAX. In fact, there is another way to do it.. but just stick with the define for now. To be honest, there are other things that could be changed, but this is what I came up real quickly.

Also, check an earlier post where I made a function and called it from main so that it returns the value. What you could do as well, is set a flag or an integer and then continue to the next iteration..  Now, I'm not sure what you're after but hopefully what I posted will help some. Do let me know if you need more help.

Met.

"My Terminal is my Soul"

ajastru2000

  • Guest
Re:Basic C++ Programming Help
« Reply #21 on: July 17, 2003, 12:10:12 AM »
Code:


#define MAX 5
int main(void)
{
int i, j, array1[5], array2[5];

array1[0] = '1';
array1[1] = '0';
array1[2] = '0';
array1[3] = '7';

array2[0] = '1';
array2[1] = '5';
array2[2] = '0';
array2[3] = '2';


for (i=0;i<MAX-1;i++) {
  for(j=0;j<MAX-1;j++) {
      if (array1 == array2[j]) {
        printf("we found a match at array1 element %d and array2 element %d \n", i, j);

          }
        }
    }

return 0;

}
 
 


This example code would print out:

we found a match at array1 element 0 and array2 element 0
we found a match at array1 element 1 and array2 element 2
we found a match at array1 element 2 and array2 element 2

Hi Met. above is your original codes with the output, how do I limit the match recorded to only once? Refering 2 your 2nd line output it found a match at array1 element 1 and array2 element2.  But it finds the same match again in the 3rd line output. Thanx Met.

Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Basic C++ Programming Help
« Reply #22 on: July 17, 2003, 01:38:15 PM »
If you look back in this thread, I made it into a function. Upon a match it returns a value... thus stopping it.

Try that out and play with it a little and if you still have trouble, feel free to post here again.

And I'm glad I can be a help.

Met.
"My Terminal is my Soul"

ajastru2000

  • Guest
Re:Basic C++ Programming Help
« Reply #23 on: July 19, 2003, 02:10:10 AM »
Hi Met, below is my original source code for my problem, Managed to get it print the match for each only once no repetition..thanx man.
Got one more problem, this are my arrays from a image buffer:
pixelv(i,j) and pixelv(x,y), fro every individual i,j or x,y there is a specific value(pixelv):

As per below how do i get it to scan line by line to find a match, as shown below both i & x are fixed, so only j & y changes, so starting with the first match j=254 & y=144 it must check if the pixelv is  same or not if not it should proceed to the next j+1 & y+1 and so on, if same it'l print both the values for j & i and the similar pixelv values.
Sorry Met, for the problem posing again, hope you could shed some light here. Thanx.

MbufGet2d(MilImage, 0L, 0L, IMAGE_WIDTH, IMAGE_HEIGHT, &pixelv )

for(j=254;j<401;j++)

{
for(y=144;y<291;y++)

{

x=200; i=270;

if(pixelv[j]==pixelv
  • [y])



{
fprintf(fptr,"\t%d %d %d %d\n",j ,y ,pixelv[j] ,pixelv
  • [y]);

break;
}
}
}

Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Basic C++ Programming Help
« Reply #24 on: July 20, 2003, 12:25:57 AM »
Firstly, you should know that I've never really played with 2 dimensional arrays. I'm really not sure what you're after either.. To me, it sounds like you're after the exact same thing as before, except it's two dimensional arrays and one of the dimensions is a constant ? If that's the case, just modify my original function and play with it some. If that's not the case, please try to explain again...


Here is your code (I cleaned it up):

Code: C++
  1. MbufGet2d(MilImage, 0L, 0L, IMAGE_WIDTH, IMAGE_HEIGHT, &pixelv ) {
  2.  
  3. x = 200;
  4. i =  270;
  5.  
  6.    for(j=254;j<401;j++) {
  7.        for(y=144;y<291;y++) {
  8.           if(pixelv[i][j]==pixelv[y])
  9.           {
  10.           fprintf(fptr,"\t%d %d %d %d\n",j ,y ,pixelv[i][j] ,pixelv[y]);
  11. break;
  12.           }
  13.        }
  14.    }
  15. }
  16.  
"My Terminal is my Soul"

ajastru2000

  • Guest
Re:Basic C++ Programming Help
« Reply #25 on: July 20, 2003, 08:40:13 PM »
Hi sorry Met, actually my codes were mixed up the other day.
Ok, I'l try explaining again using a different example.

1)Lets say we have a Topography map with its total length(j) and width(i) 100 x 200.
2)Each pairing of i & j has a height value of the map.
3)Now we'l take 2 horizontal straight lines, this means fixed j and a constant change of i: i.e 1st line-(50,50) - (50,100) and 2nd line-(75,60)-(75,110), can be seen j(length) for both the lines are fixed and i(width) changes.
4)The height value is contained for each j & i in the topography map buffer.
5)Now what i want the C++ to do is to find the same height value for each adjacent j's in both the horizontal lines. i.e: from the above example if (50,50)-1st line and (75,60)-2nd line has both the same height value it'l record, than it'l go to the next consecutive point of each line (50,51) and (75,61) and so on......

Hope this wil give u a clearer picture Met, thanx alot for ur patience with a beginner, and sorry for the trouble :(

Offline Metgod

  • the deranged hacker
  • Administrator
  • Forum Hero
  • *****
  • Posts: 1116
  • Country:
  • Gender: Male
Re:Basic C++ Programming Help
« Reply #26 on: July 22, 2003, 12:34:58 PM »
I didn't seem to follow this. I am very tired and not well in many ways.

Can you do me a favor and rename some of your variables ? Change the variable that specifies length to 'length', and width to 'width', etc. It really makes things easier to follow and it is actually good programming practice.

And then would you try to explain again, making it as clear as possible ?

Oh, and glad I can help this far.

Met.
"My Terminal is my Soul"