substrings

This is a discussion on substrings within the C++ Programming forums, part of the General Programming Boards category; I just made a program which searches for subtrings from a char* the hard way.
does someone have an algoritm ...

Serious

Why do you hate 'void main()' and 'gets()'?
Does someone pay you?
I use void since I'm not returning any value.
Is'nt that the standard?
And the italics might be some typo.
I copied and pasted.
And Ifound the reason for italics...
its the subscript thingi with 'i' inside.
I don't know the correction.

If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

>Why do you hate 'void main()' and 'gets()'?
Because void main is wrong and gets is unsafe. Why do you like 'void main()' and 'gets()'?

>I use void since I'm not returning any value.
Yet the standard requires main to return an int value in all cases. And since 0 is returned by default if you fall of the end of main with a modern compiler, you have no excuse for using void main. The following is valid C++:

Code:

int main()
{
}

However, this is not valid C++ unless your compiler allows it as a non-portable extension:

Code:

void main()
{
}

Therefore, int main requires less typing than void main on a conforming compiler, so only stubborn and ignorant people would use void main[1].

>Is'nt that the standard?
No, and it never has been, even as far back as K&R C. main has always returned int, and the standards reflect that history.

[1] Assuming a hosted implementation. On a freestanding implementation, there are no restrictions for main because it's not bound by the runtime environment. However, if you're on a freestanding implementation, you likely wouldn't be asking us for help.

> Why do you hate 'void main()' and 'gets()'?
Because they're flat out wrong.
"Works for me" is no defence when someone shows up at your door with a buffer overflow problem caused by your sloppy coding. Either learn to do it properly, or just get out of programming.

> Does someone pay you?
Yes, I get paid quite well thanks, for being a pretty damn good programmer who doesn't make loads of rubbish mistakes which need expensive fixing later on.
If you ever want to get a job, you can be pretty sure of lots of rejections if you fail to recognise these as common programming pitfalls at the interview.

> I use void since I'm not returning any value.
It's not up to you - the environment wants a value whether you feel like returning anything or not. If you have nothing to return, then a simple
return 0;
is all you need. How hard is that?

> Is'nt that the standard?
No. void main has never been the standard, and using gets() is just plain dumb.
I can tell that you've never read the FAQ.

> And the italics might be some typo.
Yeah, unfortunately, a subscript of i matches the italics tag.
Simply putting a space in there should fix it.

Don't ATTACK me :(

Thanks for all the replies.
But I never found what I wanted...
and about the correction for my c++ code...
My compiler is some pre-standard thingi.
I tried to download both Borland and GCC and Microsoft C++ compilers so that i can start using standrad C++.
But I nearly fainted when the down load times showed 6 to 23 hours. My phone bill would not just skyrocket; but it will cross light speed and be thrown back in time(???).

Be creative - look for copies of compilers on CD's which come with magazines, find a friend with a better IP connection and a CD burner.
Or maybe there's some local tech company would be willing to help you out. If you keep in contact with them, it'll look good at job finding time.
Or the local library....

> My compiler is some pre-standard thingi.
Yeah, so it's really not the best idea to learn a bunch of outdated stuff, only to have to unlearn it again later on.