Thread: need n00b c++ help
-
October 5th, 2004, 10:21 PM #1Junior Member
- Join Date
- Oct 2004
- Posts
- 3
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
-
October 5th, 2004, 10:52 PM #2
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!
-
October 5th, 2004, 11:05 PM #3Junior 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..
-
October 5th, 2004, 11:10 PM #4Junior 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.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Is everybody n00bs here?
By x86MeOneMoreTime in forum Linux and UnixReplies: 99Last Post: July 20th, 2003, 06:20 PM -
I wanna try linux
By ZENYO in forum Applications and Operating SystemsReplies: 40Last Post: December 15th, 2002, 01:34 PM -
hi im new!
By kidblount in forum IMO CommunityReplies: 19Last Post: August 15th, 2002, 03:52 AM



LinkBack URL
About LinkBacks



Reply With Quote

Do I sense some resentment at a woman in a man's sport, nunya? Although I feel you're right about her chances.
Is It Just Me? v233893843