Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] While loops and filters

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Kipodimkozim
Advanced Cheater
Reputation: 0

Joined: 05 Oct 2008
Posts: 94
Location: Inside your head

PostPosted: Fri Dec 26, 2008 5:01 pm    Post subject: [C++] While loops and filters Reply with quote

Hey guys,

The book I'm learning from demonstrate the use of while loops with filters by compiling this code:

Code:
#include <iostream>
#include <stdio.h>
using namespace std;

#define NEWLINE 'endl'

void main()
{
   char c;
   int linenum = 1;

   std::cout << std::dec << linenum << ": ";
   while ((c = getchar()) != EOF) {
      if (c == NEWLINE) {
         linenum++;
       std::cout << NEWLINE << std::dec << linenum << ": ";
      } else
         putchar(c);
   }
}


and using this filter "linenum <linenum.cpp> linemun.txt" to write a number at the begining of each line and saving it as a new txt file.
I had to manipulate the code to compile with VCpp6 since the book using a different compiler, other than that they're the same and I had no problem compiling it, but when I'm runnig the exe file and typing the filter all I get is an echo of the filter..
Why isnt working?

_________________
My smexy priest soon to be bishop:
[ ] Lvl 70
[ ] Lvl 100
[X] Lvl 120
[x] Genesis
[x] Zhelm
[ ] HT Pendant

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Learning C++
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Fri Dec 26, 2008 6:03 pm    Post subject: Reply with quote

'\n'... std::endl is not type char and 'endl' is not a single character...
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Fri Dec 26, 2008 7:26 pm    Post subject: Reply with quote

Code:

using namespace std;


Use that so you won't have to put "std::" in every std function.
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Fri Dec 26, 2008 8:02 pm    Post subject: Reply with quote

He is...
Quote:
#include <iostream>
#include <stdio.h>
using namespace std;
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Fri Dec 26, 2008 8:23 pm    Post subject: Reply with quote

Oh didn't see it, I was just looking at the main code.
Back to top
View user's profile Send private message
ups2000ups
I post too much
Reputation: 0

Joined: 31 Jul 2006
Posts: 2471

PostPosted: Sat Dec 27, 2008 1:44 am    Post subject: Reply with quote

sorry i cant answear right now i just woke up and my braincells still sleeps Razz

anyway a tip

when you are coding you should make the codes look clean and use alot of "return" so it will be easier to read

well this is easy to read right now but when you will start doing bigger codes

you are using "using namespace std;"
thats mean you can just write like this

cout
cin

instead of
std::cout
std::cin

(it will just look cleaner)

if you take a look at the changes i did you will see thats it is easier to read and thats make it easier to help you fix it

ps instead of use linenum++ and then show it in the text you could insert it in the text directly if you use this ++linenum

++linenum = add 1 to linenum before read linenum (prefix)
linenum++ = add 1 to linenum after being readed (postfix)

Code:

#include <iostream>
#include <stdio.h>
using namespace std;

#define NEWLINE 'endl'

void main()
{
   char c;
   int linenum = 1;

   cout << dec << linenum << ": ";

   while ((c = getchar()) != EOF) {
      if (c == NEWLINE) {
         cout << NEWLINE << dec << ++linenum << ": ";
      }
      else
         putchar(c);
   }
}
 


and your code
Code:

#include <iostream>
#include <stdio.h>
using namespace std;

#define NEWLINE 'endl'

void main()
{
   char c;
   int linenum = 1;

   std::cout << std::dec << linenum << ": ";
   while ((c = getchar()) != EOF) {
      if (c == NEWLINE) {
         linenum++;
       std::cout << NEWLINE << std::dec << linenum << ": ";
      } else
         putchar(c);
   }
}

_________________
dont complain about my english...
1*1 = 2?
Back to top
View user's profile Send private message
Kipodimkozim
Advanced Cheater
Reputation: 0

Joined: 05 Oct 2008
Posts: 94
Location: Inside your head

PostPosted: Sat Dec 27, 2008 8:44 am    Post subject: Reply with quote

Thanks guys =]]
_________________
My smexy priest soon to be bishop:
[ ] Lvl 70
[ ] Lvl 100
[X] Lvl 120
[x] Genesis
[x] Zhelm
[ ] HT Pendant

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Learning C++
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites