float routines

This is a discussion on float routines within the C++ Programming forums, part of the General Programming Boards category; ok i have made a routine for finding floats in an array of bytes. However the routine finds floats where ...

  1. #1
    Registered User cppdude's Avatar
    Join Date
    Jan 2002
    Posts
    62

    float routines

    ok i have made a routine for finding floats in an array of bytes. However the routine finds floats where it is not supposed to, and i cant understand for the live life of me why

    Code:
    float *ptr = NULL;
    for(int buffypart = 0; buffypart < READSPURT; ++buffypart)
    					{
    						ptr = (float*)&bytebuffy[buffypart];
    						if(*ptr == searchnum)
    						{
    							g_FoundCount++;
    							Addresses1[g_FoundCount] = readbase + buffypart;
    						}
    					}
    
    ok and g_FoundCount is added too many times i am sure. Why :)

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Try this.
    Code:
    float *ptr = NULL;
    for(int buffypart = 0; buffypart < READSPURT;)
    					{
    						ptr = (float*)&bytebuffy[buffypart];
    						if(*ptr == searchnum)
    						{
    							g_FoundCount++;
    							Addresses1[g_FoundCount] = readbase + buffypart;
    							buffypart += sizeof(float);
    						}
    						else
    							++buffypart;
    				}
    Last edited by swoopy; 05-16-2002 at 01:11 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-13-2009, 03:25 PM
  2. Replies: 14
    Last Post: 06-28-2006, 01:58 AM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 01:19 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 04:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21