as the title says im 3 days into learning c++, the book im reading though is (imho) put together in a weird way, i have to jump around a lot to search for answers, and since im a noob google has been a help but the answers i do find seem to assume i have more than 3 days of knowledge.. anyway here's my 2 part question.
1) does anyone know of a good ebook with practical exercises for learning what im reading? to read dry information is one thing, but to have a practical way to use it other than trigonometry, for me at least, makes what im reading stick.
2) can someone help me with this code, im sure out of the 20 things i did theres 100 better ways to do it. i just cant find the right info to do this easily, but again im just a noob. im trying to make practical exercises for myself, i was tired of adding 3 integers together in more and more complicated ways so "for fun" i came up with this app..
for now it shows what programs start with a windows system, on local machine (no current user yet) from the registry. im attempting to clean the output, and also store the results into a 2 dimensional array (like array[int][int]) so i can choose what to disable or enable in registry..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
typedef unsigned short int USHORT;
using namespace std;
USHORT startupLMR( USHORT activator )
{
if (activator == 0)
{
//flush results to temp file to be processed
//find a better cmd instead of system()
system ("reg query \"HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\">lmr.tmp");
}
else if (activator == 1)
{
//flush results to screen (unorganized.. just a filler function atm
system ("reg query \"HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\"");
}
else
{
cout << "\a error, wrong activator passed to startLMR function, fix code";
}
return 0;
}
int main()
{
char buffer[2048]={'\0'};
USHORT length, counter=0;
//call func without user interaction, for now (temp)
startupLMR(0);
//open tmp file dumped by startupLMR(), fill buffer and delete tmp file
ifstream fin("lmr.tmp");
fin.get(buffer, 2048, EOF);
fin.close();
system("del lmr.tmp");
//get actual length of used buffer for counter
length=strlen(buffer);
while ( counter<length )
{
//search buffer for 'string' REG_ for the sake of skipping its output to console
//can cause bugs if REG_* is in any startup values, find better solution
if (buffer[counter]=='R' && buffer[counter+1]=='E' && buffer[counter+2]=='G' && buffer[counter+3]=='_')
{
counter=counter+10;
}
//search buffer for 4 whitespaces and replace the first with newline
if (buffer[counter]==' ' && buffer[counter+3]==' ')
{
buffer[counter]='\n';
}
cout << buffer[counter];
counter++;
}
return 0;
}
|
how can i manipulate these strings better to accomplish similar or better output and to better build on those concepts stated earlier? remember im only 3 days into learning this stuff so please go easy.. thanks in advance.