4 Replies - 1842 Views - Last Post: 10 March 2012 - 08:02 AM Rate Topic: -----

#1 aliancemd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 07-December 10

Let me embarrass myself

Posted 16 February 2012 - 08:23 AM

I wrote a String library for console in my first year of C++ programming at college(not University, seems like people mistake this).
Here is some code:
class String {
private:
    char s[255]; //Ow, yee, let me write a long text baby, oh, wait, only 255 :(/>
    int l; // Length, good naming convention :)/>
    short error;
...
}


The >> operator:
//operator >>
istream & operator>>(istream &is,String &x)
{
    x.l=0; char k; //l - length
    while ((k=_getche()) != 13) { //13 - enter
        x.s[x.l]=k; 
        x.l++; 
        if(k == 8) {x.l-=2; cout<<char(32)<<char(8);} //8 - backspace, 32 - spacebar, Length -= 2 because backspace increments by 1 but I delete 1 instead
        if(x.l<0) x.l=0;
    } x.s[x.l]=0; //Length can't be lower than 0, don't go lower on delete
    cout<<endl; 
    return is;
} //Isn't it beautiful? :)/> The interesting thing is that I used <iostream> and still did all this crappy keyPress events


Oh, looks like I deleted the code where I was converting the String into numbers, oh, that was the real nightmare, and actually that's why I deleted it... The max number it was able to converto to was 999,999,999 :) If the number in the string was higher it was telling that the introduced number is over the limit.

Is This A Good Question/Topic? 0
  • +

Replies To: Let me embarrass myself

#2 Ryano121  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Let me embarrass myself

Posted 16 February 2012 - 08:51 AM

Its also slightly embarrassing that you spelt embarrass wrong :P
Was This Post Helpful? 1
  • +
  • -

#3 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

Re: Let me embarrass myself

Posted 10 March 2012 - 12:53 AM

I would reformat the code if I were you. Just saying :P
Was This Post Helpful? 0
  • +
  • -

#4 aliancemd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 07-December 10

Re: Let me embarrass myself

Posted 10 March 2012 - 02:24 AM

View Posthulla, on 10 March 2012 - 12:53 AM, said:

I would reformat the code if I were you. Just saying :P


This was my first year, guys were writing libraries to create and delete lists(actually I wrote the code for the guy that was doing this while I was writing my library, cause no one understood the concept of pointers in my class in this year), I keep the code cause this was an accomplishment for me back then, the library is compatible with Windows, and all flavors of *nix(Linux, Mac OS...). I don't plan to delete it :P
Was This Post Helpful? 0
  • +
  • -

#5 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

Re: Let me embarrass myself

Posted 10 March 2012 - 08:02 AM

Oh a memory :D Sorry buddy :s
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1