Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ string handler problem
#31
Quote:How old is Turbo C++?

Depends on the version. Mine is v.3.1, which is from 1992 (help -> about to find out)
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#32
Oh, man...version 1.01, copyright 1990!
*Shivers*.
I'm abandoning it...although it's extremely useful for a quick reference...for instance, if you what info on any C++ common function/keyword, just type it in and you get full coverage on what it is...
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#33
Quote:Oh, man...version 1.01, copyright 1990!
*Shivers*.
I'm abandoning it...although it's extremely useful for a quick reference...for instance, if you what info on any C++ common function/keyword, just type it in and you get full coverage on what it is...

But you can get that in the other compilers+IDEs (MSVC, DevC++, GCC, DJGPP, ...)
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#34
You get that in Dev-C++? How?
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#35
http://www.bloodshed.net/dev/doc/index.html Wink
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#36
Uber-Cool, but it's not offline, and it doesn't have an index of keywords.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#37
Quote:I was (for practice) writing a string handler in C++, that should take characters from stdin, terminated by character-code 13 (Enter), and then print them to stdout. It compiles fine (Turbo C++), but in runtime, it takes the characters, but ends after user presses enter. It doesn't print them.
Here's my code:
Code:
#include <iostream.h>    //for cout
#include <conio.h>

void outStr(char  *strOut)
{
for (int i=0; i <= 255; i++)
{
  if (strOut[i] != 0)        //if we haven't reached the terminator
   cout << strOut[i];
else
  break;
}
}

void inStr(char *strBuf)
{
for (int i=0; i <= 255; i++)
{
  strBuf[i]=getche();        //get the character
  if (strBuf[i] == 13)        //if user presses enter
  {
   strBuf[i]=0;        //null-terminate
   break;
  }
}
}
What am I doing wrong?
(Note: Some compilers need main() to return an int...if yours does need this, just change the void main() line to int main() and add "return 0;" to the end of the main() function).

You're mixing c++ (cout) with a c library (conio, getche), they use differents i/o systems.

To turn your code into c++, you must replace strBuf[i]=getche() with cin >> strBuf[i]. Or if you want to turn into conio app, replace cout << strOut[i] with cprintf("%c", strOut[i]).
Reply
#38
Beware! cprintf is not portable. Use printf.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#39
Actually, xhantt, I fixed the problem by placing a cout << endl; between the two function calls in main(). The problem was that getche() didn't increment the x-character-position, so the cout call in outStr was printing right over what user types.
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Reply
#40
Quote:...And...Turbo C++ doesn't support the string class....

what crap! Turbo C++ very well supports String Classes. Look up strng.h file(and no its not misspelled). Atleast TC++ v3.0 has it.

and iostream.h is a deprecated header so dont use it. Use iostream instead.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)