problem with passing data, again.

This is a discussion on problem with passing data, again. within the C Programming forums, part of the General Programming Boards category; Hi everyone, I encounter this problem and don't know how to get it work. Please help me! Thanks in advanced. ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    54

    problem with passing data, again.

    Hi everyone,

    I encounter this problem and don't know how to get it work. Please help me! Thanks in advanced. Sorry, somehow I can't use the code tag.
    Code:
     
    void Functionchild(int * data)
    {
            int i;
            for(i=0; i <4096; i++)
                  {
                    printf("\nValue of buffer passed %d", *data);
                   }
    }
    
    
    void FunctionFather(int *databuf){
              /* Doing some stuff */
              FunctionChild(databuf);
    }
    
    
    void FunctionGrandFa(int * buf){
              FunctionFather(buf);
    }
    
    
    int main(void)
    {
           int * buffer;
           int j;
    
           buffer = malloc(sizeof(*buffer)*4096);
           for(j=0; j<4096; j++)                 
                 {
                      *buffer = j;
                 }
           FunctionGradFa(buffer);
    
           free(buffer);
           return 0;
    }
    The values from 0 to 4096 are supported to print out in the FunctionChild, but they are not. Anyone please check out if I made any mistake.

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Try this:
    Code:
    void Functionchild(int * data)
    {
       int i;
       for(i=0; i <4096; i++)
          printf("\nValue of buffer passed %d", data[i]);
    }
    
    int main(void)
    {
       int * buffer;
       int j;
    
       buffer = malloc(sizeof(int)*4096);
       for(j=0; j<4096; j++)                 
          buffer[j] = j;
       FunctionGradFa(buffer);
       free(buffer);
       return 0;
    }
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Alternately, they could increment their original pointer and use their original code. Probably not the ideal way to do it, but it would work.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    54
    Thanks CShot!
    It works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. data structure design for data aggregation
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 05-20-2008, 07:43 AM
  2. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  3. Server recv data problem! Please help!
    By hyaku_ in forum Networking/Device Communication
    Replies: 15
    Last Post: 01-28-2005, 02:35 PM
  4. Replies: 6
    Last Post: 05-06-2003, 04:08 PM
  5. C Programming Question
    By TK in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 07-04-2002, 08:11 PM

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