Your Help Banfa

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sala
    New Member
    • Nov 2006
    • 12

    #1

    Your Help Banfa

    This is my first project, it is about arrays,librarie s and really i don't understand how to build a library; i found this project so hard that i don't know how to begin;
    can you just give any flash by how can i start my project .
    Specifications:
    In this project you will implement a set of functions in a set of libraries.You will implement four libraries: “myString.h”, “myMath.h”, “myCType.h” and “myLib4.h”. Each of these libraries will contain a set of functions to be described in next section. Some of the functions are original ones; others are to overwrite some well-known functions.
    Functions List:

    “myString.h”: (3)
     void mystrncpy(char* , const char*, int)
     void mystrcmp(const char*, const char*)
     int mystrlen(const char*)

    “myMath.h”: (3)
     double myPower(double, int)
     int mycCeil(double)
     double myExp(double) // use the formula you had in a former quiz (Do Sum 200 terms)

    “myCType.h” (5)
     int getAscii(char); // returns the corresponding ASCII code (Not in “ctype.h”)
     int myIsAlpha(char) ;
     int myIsDigit(char) ;
     int myIsAlnum(char) ;
     char myToUpper(char) ;

    “myLib4.h”: (7)
     void convertStringTo Upper(char* s);
     void invertString(ch ar* s) ;
     void sortString(char * s); // alphabetically/
     void removeSpaces(ch ar* s);
     int stringTokenizer (char* s1, char* s2); // returns 1 if s2 is a sub-string of s2, zero otherwise ( stringTokenizer (“totofoo”, “of”) returns 1)
     int isPalindrome(ch ar* S); // returns 1 one if S is a palindrome, zero otherwise
     void removeStrings(c har list1[][10], int* size1, const char list2[][10], int size2); // removes the words in list2 from list1;
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    I'm obviously not Banfa, but....

    Basically,the *.h files are the definitions of the library. If they haven't been provided, you can copy the prototypes into the relevant files almost exactly how you have listed them. That is, myString.h can be listed as:
    Code:
    void mystrncpy(char* first, const char* second, int length);
    void mystrcmp(const char* first, const char* second);
    int mystrlen(const char* inputString);
    Now you can make a file myString.c which implements these methods (incidentally, I syspect mystrcmp should return something {probably an int});

    mystrncpy copies the first n characters at second (or the entire string if length less than n) to first (using the variable names we used above).

    mystrcmp compares two strings. Usually this type of function returns whether the strings aren't the same (that is, by convention, it returns 0 if the strings are the same, a +ve number if the first is alphabetically first and a -ve number if the second is alphabetically first). This may sound complicated, but it sort of comes naturally (ie return the difference of the last character you check)

    mystrlen is a simple while loop that counnts the characters in a string until it finds the null terminator. (In c Strings are character sequences that are terminated by a null character)

    in myMath.h:
    myPower can be implemented using a for loop to multiply the exponent by itself.

    mycCeil is a rounding function many ways to implement from casting to iterating through taking away 1 each time (and counting how many times) until you are below 0.

    myExp you have solved in a previous assignment it would appear.

    That's a start, more coming......

    Comment

    • DeMan
      Top Contributor
      • Nov 2006
      • 1799

      #3
      for this section, remember that a char is a 1byte integer (and in c can be treated as such)

      in myCType.c
      getASCII can probably be done with a cast from char to int.

      myIsAlpha needs to compare whether the character is in the range of uppercase and lowercase letters (you can find an ASCII table on the net - I think Uppercase start around 65 and lowercase around 95 )

      myIsDigit CAREFUL!!! - The ASCII code for digits (in the table you found for the previous function) are NOT their values, that is (and I'll try not to be confusing) the ASCII code for 1 IS NOT 1.

      myIsAlnum can test one or the other from above.

      myToUpper in your ASCII table you will have noticed that the uppercase characters are a fixed (-32 I think) distance from their lowercase counterparts. Test to make sure the character is a lowercase digit, then return that - 32.

      myLib.c:
      convertStringTo Upper iterate through your string calling myToUpper (you may need to include some files from your library)

      invertString (I assume this means turn the String around) so iterate from back copying into new string

      sortString if your allowed to convert all to upper do that then sort is trivial(ish), you still need to take into account special characters. If you can't do this be aware that (as far as I know) alphabetically speaking 'apple' and 'APPLE' are equal, so you may need to take into account that csorting by character values needs to take into account upper- and lowercase letters .

      removeSpaces We're probably getting good atr iterating through our String by now, copy it into temp variable and copy non whitespace characters back (and remember to Null terminate)

      stringTokenizer look for the first character of secondstring in first, if found compare next, if not found try further through the string. There are some traps here, but by the time you get this far you will be an expert (and by then by all means post your efforts and ask for help).

      isPalindrome many ways to do this, probably the most intuitive is to have two pointers, one at the start one at the back and iterate (or recurse if you feel confident) through toward the middle while the strings are the same. You may need to only consider characters (that is... radar is obviously a palindrome, but should you recognise "Rise to vote, sir" or "Madam I'm Adam") In this case you can use the functions above to strip non alphabetic characters and spaces out of your String before starting palindrome test.

      removeString compare words in list 2 and if you find them in list 1 remove them (if you get confused hear, it's might be because strings can be though of as char arrays - hence the 2 dimenional array for a list). You may like to clarify what remove means, (ie does it mean replace with null, or replace with null and move to the bottom of the array.

      Hope All Goes Well & Happy Coding

      Comment

      • thefarmer
        New Member
        • Nov 2006
        • 55

        #4
        well what ca i say DEMAN explain all this stuff to you, hes " DEMAN"

        regards,

        Comment

        Working...