It's just a function that takes a string as an argument and merely loops till it finds the terminating NULL character.
[...]
Am i doing something wrong?
Yes. To find the terminating char, you did this: while (s[n] != 0)
But 0 and the string-terminating-char aren't the same. So change it to: while (s[n] != '\0')
Now your array will stay within it's limits.
Just a hint: You can also use strlen () which does the exact same thing, but with a lot of error checking.
Also: this thread is in the wrong forum. I'll ask if it can be moved.
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
turbo C is a piece of crap.
use the GCC compiler (free) or MSVC compiler (free) with the Code::Blocks IDE (free).
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
hi. Paolo. i wish i had an answer for you. i would try, but i don't have the compiler to replicate it with.
well, i can see now you're not the typical Turbo C user who just doesn't know any better. ... so if you don't mind, i'd like to know why do you need to use it? curious.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
The program you're writing will work on ANY C compiler, even piece of crap compilers, which Turbo C is not one of. It pisses me off every time someone denegrates good compilers just because they are older. If they do exactly what the user needs, it's fine. It just can't do advanced 32bit stuff that the user obviously doesn't need. It still is C. It still works fine. And TC can still do things none of the current compilers can do.
I agree upgrading should be considered, but is not necessary. And definitely TC should not be put down.
WaltP
Posting Sage w/ dash of thyme
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
I don't have Turbo C 2.0, but this runs fine in Turbo C/C++ ver. 1.01, as a C program. Note int main and the include header.
IIRC Turbo C 2.0 came before Turbo C/C++, but it's been a long time.
#include <stdio.h>
void f(char *);
char h[] = "hello";
int main() {
int gar;
f(h);
gar = getchar(); gar++;
return 0;
}
void f(char *s) {
int n = 0;
while (s[n] != '\0') {
/*do something*/
putchar(s[n++]);
}
}
Adak
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185
I compiled from the IDE.
If using int main doesn't help correct your program's starting address, can you just set the address, explicitly?
Adak
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185
wait a minute.... you're using "void main()" ?? LOL ... how did we not see this. You know, of course, "void main()" is undefined.
so it's no wonder you're having undefined behavior.
i dont think that borland would release a buggy compiler
oh, it was a great compiler....in 1989. now its just full of deprecated, non-ANSI functions and terribly non-portable. Borland's strategic business plan appears to hinge on an exclusive distribution contract with the government of India, but other than that, i can't imagine why anyone would choose to use it.
.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
My version, which has int main, instead of void main, works fine using: "tcc
And I did notice it! :)
Adak
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185
yeah, you did. good spot. :) ... by "we" i meant the various "veteran" forum members who have passed through this thread over the past week. (where's Salem, anyhow??)
(i think what happened here is everyone saw "Turbo C" and said PFFFT... or maybe we all got skeered by the assembly :P )
.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
sorry, man, i don't have Turbo C.
one time, i thought about installing it for fun, but they wanted a whole bunch of registration and personal info B.S.
which just reinforced the fact that i didn't want their crap on my hard drive, anyhow.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179
The -mt option gives me this "warning: No Stack".
I don't believe the borland compiler is buggy, but I do believe you'll need to do some research, perhaps on a website dedicated to borland's legacy compilers, and see what's the right way to do this.
I'm new here. Do you have any old timer's who might remember how this is done with Turbo C, around? :)
Wish I could help you out, but I have never worked with separate compilation, and linking.
Adak
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185
i cant even get exe2bin to work on my Vista laptop. it's a native DOS application, for one thing.
what kind of hardware and OS are you running/compiling all this on? If you're trying to do 16-bit computing on modern machines, you're gonna have major difficulties.
i dont even trust EXE2BIN to work correctly, there's so many limitations of that program as it is, and now you want it to disassemble a third-party executable.
i think this approach (Turbo C + MSDOS Exe2Bin) is just doomed from the start.
jephthah
Posting Maven
2,587 posts since Feb 2008
Reputation Points: 2,143
Solved Threads: 179