AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: avdate — October 6, 2006
    +2 votes
      + -

    #include <stdio.h>
    main() {
    char *x= “acbcd”;
    char y = ‘c’;
    int len = strlen(x);
    int i=0,j=0;
    for( i = len-1; i>= 0; i– ) {
    if ( x[i] == y ) {
    break;
    }
    }
    printf(”%s%c%s%d%s”,”the # of last occur of “,y,” is “,i+1,”n”);
    }

  2. Submitted By: NovusAmor — October 6, 2006
    +6 votes
      + -

    avdate your solution is to slow.

    char *lastchar(char *pszStr,char chMatch)
    {
    char *pchrtn = NULL;

    while( *pszStr++ != NULL )
    if( *pszStr == chMatch ) pchrtn=pszStr;

    return pchrtn;
    }

  3. Submitted By: amit_karnik — October 6, 2006
    -2 votes
      + -

    too slow is avery dicey term. If its a very long string then it make a lot of good sense to start from the end.

    in such a case your solution would be “too slow”

  4. Submitted By: deep — October 6, 2006
    +1 votes
      + -

    int lastinstance(char *s, char c)
    {
    int x=strlen(s);
    for(; x>=0;x–)
    {
    if(s[x]==c)
    return x+1;

    }
    return 0;
    }

  5. Submitted By: jj — October 6, 2006
    +2 votes
      + -

    Doesn’t strlen() do a forward scan until it finds ‘’? If so, then calling strlen() and then starting from the end is actually slower than starting from the begining. Not much, but a little bit.

  6. Submitted By: Ben Hanna — October 16, 2006
    -8 votes
      + -

    C functon
    ————-
    - you have have this preprocessor
    #include

    char Last_Char(char *Str)
    {
    return Str[strlen(Str) -1] ;
    }

    C++
    ——
    - you have have this preprocessor
    #include

    char Last_Char(string Str)
    {
    int final = Str.size() - 1 ;
    retun Str.at (final);
    }

  7. Submitted By: Steve Bush — November 22, 2006
    +1 votes
      + -

    Assumes psz is a NULL terminated string (if you have a length then use psz+cch and work backwards). Returns a pointer to the last character found.

    char *PchLastChar(char *psz, char chToFind)
    {
    char *pchLast = NULL;

    while (*psz)
    {
    if (*psz == chToFind)
    pchLast = psz;

    psz++;
    }

    return pchLast;
    }

  8. Submitted By: Sunny — June 23, 2007
    -1 votes
      + -

    Here is the solution to this in C# (not using any string internal function such as indexOf, lastIndexOf)

    private int GetLastInstanceIndex(string input, char c)
    {
    //decl
    int count;
    bool found;

    //init
    count = 0;
    found = false;

    if (input == “” || input==null)
    return -1;
    // get the string into an array of characters
    char[] arrInput = input.ToCharArray();

    for (count = arrInput.Length - 1; count >= 0; count–)
    {
    if (arrInput[count] == c)
    {
    found = true;
    break;
    }

    }

    if (found)
    return count;
    else
    return -1;

    }

  9. Submitted By: Arijit — July 15, 2007
    not yet rated
      + -

    #include
    int substr(char *x,char y);
    int main()
    {
    char *stringIn=”testing”;
    int i;

    i=substr(stringIn, ‘g’);
    printf(”The Last Occurence of the alphabet is %d”, i);

    }
    int substr(char *x,char y){
    int i=0;int j=0;
    for( ;*x!=”;j++){
    if(*x==y){i=j;}
    x++;}

    return i;}

    This gives the relative position.

  10. Submitted By: vinay — October 9, 2007
    -1 votes
      + -

    Scan both sides of string in a single for loop:

    int lastIndexOf(char *phrase, char match)
    {
    int len = strlen(phrase);
    char array[len];
    int pos = -1;
    //convert the dam thing to char array
    for(int i = 0; i pos)
    {
    pos = i;
    break;
    }
    }
    if(array[i] == match)
    {
    pos = i;
    }
    if(array[len-i] == match)
    {
    pos = len-i;
    }
    }
    return pos+1;
    }
    //if the characters are even
    else
    {
    for(int i=0; i

  11. Submitted By: tik — April 12, 2008
    not yet rated
      + -

    C++

    compiled by g++

    #include
    #include
    #include

    using namespace std;

    bool IsAlpha( char x ) { return isalpha(x); };

    main() {
    string test = “abcdjk jfdjl jlsj !#@”;
    cout

  12. Submitted By: tik — April 12, 2008
    not yet rated
      + -

    using namespace std;
    bool IsAlpha( char x ) { return isalpha(x); };

    string test = “abcdjk jfdjl jlsj !#@”
    *find_if( test.rbegin(), test.rend(), IsAlpha );

  13. Submitted By: niskam — July 3, 2008
    not yet rated
      + -

    void main()
    { char *p=”niskam”
    while(*p)
    { p++; }
    p–
    printf(”%c”,*p);
    getche();
    }

  14. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.