Thread: Help explain what this code does? Step by step please.. :D thanks! (About pointers)

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    33

    Help explain what this code does? Step by step please.. :D thanks! (About pointers)

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    
    int main()
    {
        int size = 0, counter = 0;
        char *data = calloc(size, sizeof(char));
        int length = 1, counter1 = 0;
        char **input = 0;
        do
        {
            input = realloc(input,sizeof(char*) *length);
            printf("Enter a word:");
            size = 0;
            free(data);
            data = 0;
    
            do
            {
                size++;
                data = realloc(data, size+1);
                *(data+size-1) = fgetc(stdin);
            }
            while(*(data+size-1) != '\n');
    
            data = realloc(data, size+1);
            *(data+size) = 0;
            input[counter1] = calloc(size+3, sizeof(char));            
            strcpy(input[counter1], data);
            length++;
            counter1++;
        }
         while(strcmp(input[counter1-1], "end\n") != 0);
    
        counter=0;
    
        while(counter < counter1)
        {
            printf("%s", input[counter]);
            counter++;
        }
            
        
    }
    Help explain what this code does? Step by step please.. thanks!

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Nope. This looks too much like a homework exercise (and that runs you afoul of the homework policy here). Even if it isn't a homework exercise, you will learn more by doing your own work to explain what the code does than you will if someone else spoon-feeds you.

    If you make an honest effort, people will be more willing to help.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Step by step read data from exe file to memory.
    By JoBlack in forum C++ Programming
    Replies: 1
    Last Post: 06-23-2012, 02:02 PM
  2. Replies: 4
    Last Post: 05-26-2011, 06:51 AM
  3. multiplying step by step
    By Martin0027 in forum C Programming
    Replies: 1
    Last Post: 05-18-2011, 11:03 AM
  4. why does the memory increase step by step?
    By zcrself in forum C Programming
    Replies: 9
    Last Post: 07-14-2010, 12:04 AM
  5. Replies: 6
    Last Post: 01-03-2003, 05:40 PM