cant see the logic of this line..

This is a discussion on cant see the logic of this line.. within the C Programming forums, part of the General Programming Boards category; table is an array of 3 which stores three rows of each file it returns the dmallest id why they ...

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    cant see the logic of this line..

    table is an array of 3 which stores three rows of each file
    it returns the dmallest id

    why they use
    Code:
    *index=i;
    for what purpose
    ??
    Code:
    int getMin(int eof[],vote table[],int *index){
    	int i,idmin;
    	for(i=0,idmin=999999999;i<3;i++)
    		if(eof[i]!=EOF && table[i].id<idmin){
    				idmin=table[i].id;
    				*index=i;
    		}
    	return idmin;			
    }

  2. #2
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    index is a pointer, it holds a memory location
    *index = i puts i inside the memory location index is pointing to

    for example
    Code:
    int main()
    {
      int bar = 4;
      int *foo = &bar;
      *foo = 7;
      printf("%d", bar);
      return 0;
    }
    the output will be : 7

    it also allows the manipulation of variables outside the scope of the subroutine
    Last edited by ಠ_ಠ; 04-05-2009 at 04:21 PM.
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Well, I suppose the the logic is very simple. Since the function cant return more than one value. But the person who coded it looks like the that he wanted the index value if the table of where the min value was found. And that he is doing. As soon the min value is found, it function also return the index value of where the min value was found in tables array.

    -ssharish
    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading a file line by line
    By Raskalnikov in forum C Programming
    Replies: 8
    Last Post: 03-18-2009, 11:44 PM
  2. Pointer and Polymorphism help.
    By Skyy in forum C++ Programming
    Replies: 29
    Last Post: 12-18-2008, 08:17 PM
  3. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 03:13 PM
  4. Finding carriage returns (\c) in a line
    By JizJizJiz in forum C++ Programming
    Replies: 37
    Last Post: 07-19-2006, 05:44 PM
  5. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM

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