|
<sigh> normally i don't like to answer homework questions, but ...
Without error or roll-over checking the following does what you want.
If you were to hand in as shown i would fail you.
Put in error and roll-over checking and maybe expand to make more readable.
void encrypt( char e[] )
{
for( int i = 0; e[i]; e[i++]++ );
}
void decrypt( char *ePtr )
{
while( *ePtr ) (*(ePtr++))--;
}
...cmk
Save the whales - collect the whole set
|
|
|
|
|
/*
Quaydogg wrote:
Basically this program turns a character into the next letter of the alphabet. For example t becomes u, h becomes i,spaces become exclamation points, etc.
Your synopsis of the problem is close but not 100% correct. As you have stated spaces become exclaimation points. When did spaces become part of the Roman alphabet?
From your very limited example I think what is more likely happening is that you are incrementing and decrementing ASCII character codes. The example string you provided does not have sufficient information to make this statement unequivocally because there is no Z or z in the string but since space (ASCII 0x20)) ==> ! (ASCII 0x21) and ! (ASCII 0x21) ==> " (ASCII 0x22) it looks like that is what is happening.
You should probably verify this with your professor because if you are rotating alphabetic characters than "Z" (ASCII 0x5a)would become "A" (ASCII 0x41) and "z" (ASCII 0x7a)would become "a" (ASCII 0x61) in the encryption routine. If you are incrementing ASCII character codes "Z" (ASCII 0x5a) ==> "[" (ASCII 0x5b)and "z" (ASCII 0x7a) ==> "{" (ASCII 0x7b) and your algorythm is a lot simpler to implement.
I digress, onto the more pressing problem.
Quaydogg wrote:
The objective of this lab is to use pointer notation to make the program do this but I don't understand pointers too well. If someone could get me started on this program I'd appreciate it.
I could give you code that solves the encryption and decryption problem but then you would still not understand pointers which is, in fact, the point (pun intended) of this whole exercise in the first place.
Instead I will provide you with a few illustrations of pointers at work and try to explain what is going on so that, hopefully, you will understand the process more clearly.
To start off pointers, as their name implies, point to something.
This is different than being something as I will attempt to explain.
A pointer is an address of a variable, structure, array, function, etc.
You can reference the thing pointed to by use of the pointer.
The semantics of pointers may be a bit confusing at first but work through it and they will become easier to understand.
In the following examples I will be using cahracter arrays but pointers are by no means limited to strings.
As I said before the pointer is an address of a thing. When you preface the pointer with an asterisk "*" you are working with the actual thing you are pointing to. Individual elements of the character array in the following examples.
Do not confuse this with the asterisk in the type definition of the pointer (i.e. char*, int*, long*, etc.). If you are referencing the pointer you do not use the asterisk, but if you are referencing the thing pointed to you do use the asterisk. A bit confusing at first.
I hope these examples will help you to understand pointers a little better.
*/
#include <stdio.h> // needed for printf
void fn1(char*);
/*
void fn1(char e[]);
This function prototype is perfectly legal also
I just wanted to point out that "char e[]" and "char*"
are the same (a pionter to an array of characters)
*/
void fn2(char e[]);
void fn3(char*);
void fn4(char*);
/* notice how the second parameter passed to function main is "char* argv[]" (pointer to an array of pointers) */
int main(int argc, char* argv[]){
char szString[] = "Hello World!";
fn1(szString);
fn2(szString);
fn3(szString);
fn4(szString);
return 0;
}
void fn1(char e[]){
/* while the thing being referenced (characters in an array) is not null ('\0') */
/* every time the string is printed the pointer is advanced one character position */
while(*e)
printf("fn1 - %s\n", e++);
printf("\n");
}
void fn2(char e[]){
/* the pointer stays the same (pointing to the beginning of the array) */
/* the array index is incremented with every itteration of the loop */
/* eventually the array element equals null ('\0') and the loop terminates */
for(int i = 0; e[i]; i++)
printf("fn2 - %c\n", e[i]);
printf("\n");
}
void fn3(char *ePtr){
/* while the thing being referenced (characters in an array) is not null ('\0') */
/* every time the string is printed the pointer is advanced one character position */
while(*ePtr)
printf("fn3 - %s\n", ePtr++);
printf("\n");
}
void fn4(char *ePtr){
/* the pointer stays the same (pointing to the beginning of the array) */
/* the array index is incremented with every itteration of the loop */
/* eventually the array element equals null ('\0') and the loop terminates */
for(int i = 0; ePtr[i]; i++)
printf("fn4 - %c\n", ePtr[i]);
printf("\n");
}
/*
Program Output:
fn1 - Hello World!
fn1 - ello World!
fn1 - llo World!
fn1 - lo World!
fn1 - o World!
fn1 - World!
fn1 - World!
fn1 - orld!
fn1 - rld!
fn1 - ld!
fn1 - d!
fn1 - !
fn2 - H
fn2 - e
fn2 - l
fn2 - l
fn2 - o
fn2 -
fn2 - W
fn2 - o
fn2 - r
fn2 - l
fn2 - d
fn2 - !
fn3 - Hello World!
fn3 - ello World!
fn3 - llo World!
fn3 - lo World!
fn3 - o World!
fn3 - World!
fn3 - World!
fn3 - orld!
fn3 - rld!
fn3 - ld!
fn3 - d!
fn3 - !
fn4 - H
fn4 - e
fn4 - l
fn4 - l
fn4 - o
fn4 -
fn4 - W
fn4 - o
fn4 - r
fn4 - l
fn4 - d
fn4 - !
I hope this helps you to understand pointers and their uses.
As you can see the way you prototype a function (char *p) or (char p[]) has no effect on the way pointers operate.
You will probably want to insure that the loops end after some arbitrary number of itterations so that the loops don't go longer than expected but longer than expected is a subjective evaluation.
As you may or may not have realized by using pointers you are altering some area of storage off somewhere that may have unexpected results if the strings are not terminated properly. A non destructive way to determine this is to pass the string pointer to the function strlen() and make a decision based on the return value. In this way you have not already altered some storage off somewhere before you realize that this is getting to be a very long string.
*/
|
|
|
|
|
I have a Problem with casting a CString to Char.
I made this Function
char * GetCommand(void)
{
return (char*)&this->m_sCommand;
}
m_sCommand is a CString and the calling class needs to get a pointer to a Char Array.
It doesn't work the way I made it. Its no Error, but silly Data.
I don't know, how big m_sCommand is, so it all has to by dynamic.
Does anybody understand my problem?
Please help me, if You can.
Greetings
Gerhard from Germany
|
|
|
|
|
<font style="color:blue;">char</font>* GetCommand(<font style="color:blue;">void</font>) {
<font style="color:blue;">return</font> (LPCTSTR)<font style="color:blue;">this</font>->m_sCommand;
}
TOXCCT >>> GEII power
|
|
|
|
|
Thank you for quick answer.
I did it and got compiler error:
error C2440: 'return': 'ATL::CSimpleStringT<basetype,t_bmfcdll>::PCXSTR' kann nicht in 'char *' konvertiert werden
Try to translate:
error C2440: 'return': 'ATL::CSimpleStringT<basetype,t_bmfcdll>::PCXSTR' can not be convertete to 'char *'
What now?
|
|
|
|
|
But with
const char* GetCommand(void) {
return (LPCTSTR)this->m_sCommand;
}
it is working. Now I have tr test, where to change on other places.
|
|
|
|
|
yes, i didn't mentionned that the LPCTSTR type was a typedef of the const char* one.
sorry for my mistake.
TOXCCT >>> GEII power
|
|
|
|
|
You are taking the address of an instance of a CString and casting it to a char*. That will not work as you have discovered. If you use 'toxcct' response you should find that may work fine. What that response does is use CString's ability to convert itself to a char*. However the pointer you are given is a const pointer and you are then casting away the const'ness. As long as you do not try to change the buffer contents that the pointer points to, you will be fine. But if you need non-const access, you will need to code this differently. Probably through some kind of Set method.
Chris Meech
I am Canadian. [heard in a local bar]
I think people should be required to have an operator's permit to use the internet. John Simmons
I have a feeling that if the millions of man hours wasted every year by geeks trying to get various video and sound cards working under Linux were put into some useful endeavor we'd have solved world hunger, we'd have peace and aids would be no more. [JOS poster]
|
|
|
|
|
what about sprintf()?
[insert witty comment here]
bdiamond
|
|
|
|
|
You should copy the data to buffer either supplied in the argument list or to a global buffer if you are not planning on doing anything extreme with it.
|
|
|
|
|
Which is better from overall performance point of view - Creating a shared memory (~100MB) on the paging file, or on a separate disk file?
Thanks,
Krishnan
|
|
|
|
|
There is a key in the registry
UninstallString which contains a Path such as
C:\WINDOWS\system32\UNWISE.EXE C:\WINDOWS\system32\myodbc3_install.LOG
or
rundll32.exe setupapi.dll,InstallHinfSection DefaultUninstall 132 C:\WINDOWS\INF\PCHealth.inf How do i check that these Paths exists and the uninstall entry in the registry is good.
Parsing it seems to be a real pain
Is there a way by which i can ask windows that or i am stuck with writing a BIG BUGGY parsing algo cause there are tons of different types of entries
any help or suggestion will be welcomed
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
http://www.mastishk.com
|
|
|
|
|
mailMonty wrote:
How do i check that these Paths exists...
Do you mean with something like _access() ? If not, please explain the problem further as I do not understand exactly what the goal is.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
always so concise in your answers dear David... i appreciate ! ;)
TOXCCT >>> GEII power
|
|
|
|
|
As Steven Covey says:
"Seek first to understand, then to be understood."
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi,
How do I initilaize an array whose size will be determined by an user input(For example from a edit box ?
I tried this but they didnt work...
numsamples = m_numsamp;
const long arr = numsamples;
ULONG x[arr];
ULONG y[arr];
They returned error 2057 and 2466.
Thanks!
Deepak Samuel.
|
|
|
|
|
You need to dynamically allocate your array. This is where pointers comes very handy!
ULONG* arrA = NULL;
int nSize;
<font color=green>
..
<font color=green>
arrA = new ULONG[nSize];
if(NULL != arrA)
{
<font color=green>
arrA[0] = 1234;
cout << _T("yeah baby!") << arrA[0] << endl;
<font color=green>
delete [] arrA;
{
I Dream of Absolute Zero
|
|
|
|
|
Hello,
Does anybody know if you can 'disable' the beep when calling an AfxMessageBox? This is quite annoying.
tnx!!
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
I don't think you can switch it off programmatically from the ::MessageBox() function.
Have a look in your Control Panel, under 'Sounds, Speech, and Audio Devices'. You can control the WAV associated with a windows event, including the message box sound(Default Beep). You can even choose to switch it off from there.
I Dream of Absolute Zero
|
|
|
|
|
I have an application which starts another application, but I dont need to see the dialog window of this other program. The user can maximise it if required.
I have tried the following to hide the dialog window in the program:-
this->OnShowWindow (FALSE, 0);
<br />
and this->ShowWindow (SW_HIDE);
but the dialog wind is still visable.
I start the program via CreateProcess (see below):-
::ZeroMemory(&si[0], sizeofsi[0])); <br />
GetStartupInfo(&si[0]);<br />
si[0].dwX = 0;<br />
si[0].dwY = 0;<br />
si[0].dwFlags = STARTF_USEPOSITION;<br />
CreateProcess( NULL, <br />
"c:\\Program Files\\Joystick\\MSCPP.exe",
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si[0],
&pi[0]);
Any comments please as I am sure a simple solution exists.
|
|
|
|
|
Just change your startup information:
sweep123 wrote:
si[0].dwFlags = STARTF_USEPOSITION;
Try this:
si[0].dwFlags = STARTF_USEPOSITION | STARTF_USESHOWWINDOW;<br />
si[0].wShowWindow = SW_MINIMIZE;
cheers,
Rich
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Thanks, but no luck.
The program window is NOT minimised.
|
|
|
|
|
try ShellExecute
Last parameter set it to SW_HIDE
or ShellExecuteEx
or LoadModule()
gabby
|
|
|
|
|
Does the dialog have a minimise button? If it doesn't, you can't minimise it.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hello...
I need to run an external program, suspend at some offset, retrieve register values(like ebx) and continue running external app.
That is the problem
How do run-time patchers work?
P.S.: Please reply to ths@smtp.ru
Thanks...
|
|
|
|