Strange Output

This is a discussion on Strange Output within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> #include<stdlib.h> #define blockSize 16 #define blockSide 4 int bType[28] = {6,10,14,15,10,11,14,15,7,11,14,15,10,13,14,15,9,10,14,15,10,11,13,14,3,7,11,15}; int main() { int *tBlock,type = 0,i; ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    66

    Strange Output

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    #define blockSize 16
    #define blockSide 4
    
    int bType[28] = {6,10,14,15,10,11,14,15,7,11,14,15,10,13,14,15,9,10,14,15,10,11,13,14,3,7,11,15};
    
    int main() {
    
        int *tBlock,type = 0,i;
    
        tBlock = (int*) calloc(blockSize,sizeof(int));
    
        for(i=0;i<blockSize;++i) tBlock[i] = 0;
    
        for(i=(blockSide*type);i<blockSide*(type+1);++i) tBlock[bType[i]] = type;
    
        for(i=0;i<blockSize;++i) printf("&#37;d ",tBlock[i]);
    
        free(tBlock);
    
        return 0;
    
    }
    This code is a piece of a tetris game and it should set for each type of block, the corresponding value at the right index.
    Th problem comes when I set type = 0, then the output will be all zeros.
    This is very strange because the other numbers from 1 to 6 will give the right values.

    Why is this happening? I can't seem to find any error...
    Last edited by ThLstN; 04-05-2008 at 12:23 PM.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    I set type = 0, then the output will be all zeros
    tBlock[bType[i]] = type;
    And what do you expect it to be assigning zeroes?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    66
    Oh silly me... That's the problem...
    Thanks for your help...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Output an array in a textbox
    By Diablo02 in forum C# Programming
    Replies: 5
    Last Post: 10-18-2007, 03:56 AM
  2. Binary Search - Strange Output
    By mike_g in forum C Programming
    Replies: 13
    Last Post: 06-16-2007, 02:55 PM
  3. Connecting input iterator to output iterator
    By QuestionC in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2007, 02:18 AM
  4. Trying to store system(command) Output
    By punxworm in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2005, 06:46 PM
  5. Really strange, unexpected values from allocated variables
    By Jaken Veina in forum Windows Programming
    Replies: 6
    Last Post: 04-16-2005, 05:40 PM

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