Need explaination of the following function

This is a discussion on Need explaination of the following function within the C Programming forums, part of the General Programming Boards category; Does anyone know what is the following two function does. Can i have an explaination of that?? Code: void reverse(char ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    49

    Need explaination of the following function

    Does anyone know what is the following two function does. Can i have an explaination of that??

    Code:
    void reverse(char s[])
    {
      int i=0,j;
      char a,b;
      j=strlen(s)-1;
      while(i<j)
     {
     	a=s[i];
      	b=s[j];
      	s[j--]=a;
      	s[i++]=b;
     }
     s[strlen(s)]='\0';
    }
    Code:
    void itoa(int i)
    {
    	int back=0;
         do {
              fil[back]= i % 10 + '0';
              i =i/10;
    //	  printf ("%d", i);
    	  back++;
         } while (i>0);
         fil[back]='\0';
         reverse(fil);
    }

    Thanks
    diana --> programming is tough

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    It would appear that the first function reverses the order of characters in a string, while the second converts an integer into a character (itoa() is a standard C function - but with a different prototye). I find it odd that neither function returns anything - where did you find these?

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by sean_mackrory
    itoa() is a standard C function
    Huh?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    atoi()

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    4
    both functions do not need to return any values because they store the result in arrays and the result can be accessed from other functions from this array. First function reverses a given string by interchanging first and last character, then the 2nd and last but one and soon and at last appends a null character to the reversed string. Second funciton converts a number to its string equivalent. This is done by adding the digits to '0' to get the ascii value of that number. At last the whole string is reversed.

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Huh?
    atoi()
    Ah!.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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