+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Oct 2004
    Posts
    3

    Exclamation need n00b c++ help

     
    hey all: i am in my second semester of c++ programming, and that is the extent of my experience with it. im looking for some help:

    i cant figure out how to find the substring by modifying the following code:

    char *mysubstr(char *substr, const char *src, int first, int length){
    // returns substring of src starting at position "first" and having the size "length"
    char *rez = substr;
    char *srcstart = first;

    if (((first < 0) || (length < 1)) || (length > sizeof src))
    {
    substr = '\0';
    }
    else
    {

    for (;*src != '\0';src++);
    for (; ;*substr = ;substr++)

    }
    return rez;
    }

    it's supposed to be what the library uses, so i cant use any library calls. i just need to complete the code.

    int first = the location of the first letter of the substring on the source string
    length = the length of the substring off of the first location

    thanks alot. this is my first post here, so hello all!

    Jesse

  2. #2
    I am a banana! originel's Avatar
    Join Date
    Jun 2002
    Location
    Texas Tech
    Posts
    3,921
    the first thing i notice is that this is a rather odd style. obviously some stuff was left out of the of the loops among other things.

    are you allowed to change what is there? personally i think it's rather poor programming style to have that type of conditional in a for loop. that's just my opinion though. also the "*substr =" should be "*substr == X" where X is something else.

    also i will say that the first for loop is probably to find the length of the string, or at least the length of something most likely. The second is where the actual substring is copied.

    also, why is the substr pointer passed if it returns the value? honestly this is not a good way of approaching the problem.

    the first easy thing i noticed is that it should be sizeof(src) instead of sizeof src in the if statement.

    btw, welcome to techimo!

  3. #3
    Junior Member
    Join Date
    Oct 2004
    Posts
    3
    thanks alot!

    i will try to mod the code. yes, i agree it is an odd style. i will try to fix the things that are messed up and try it..

  4. #4
    Junior Member
    Join Date
    Oct 2004
    Posts
    3
    attached is the entire project so you can see what the deal is. we are supposed to try to figure out what the code is in the libraries, so we know how the things work that we utilize.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Is everybody n00bs here?
    By x86MeOneMoreTime in forum Linux and Unix
    Replies: 99
    Last Post: July 20th, 2003, 06:20 PM
  2. I wanna try linux
    By ZENYO in forum Applications and Operating Systems
    Replies: 40
    Last Post: December 15th, 2002, 01:34 PM
  3. hi im new!
    By kidblount in forum IMO Community
    Replies: 19
    Last Post: August 15th, 2002, 03:52 AM

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews