Copyright 2004 by M. Uli Kusterer Tue, 30 Dec 1969 07:58:58 GMT Comments on article book8 at Zathras.de http://www.zathras.de/angelweb/book8.htm book8 Comments witness_dot_of_dot_teachtext_at_gmx_dot_net (M. Uli Kusterer) witness_dot_of_dot_teachtext_at_gmx_dot_net (M. Uli Kusterer) en-us Comment 14 by Kevin Hopcraft http://masters-of-the-void.com/book8.htm#comment14 http://masters-of-the-void.com/book8.htm#comment14 Thank you for your 'books'. They are very helpful.

I never understood any other books on programming, they just didn't explain it well. You actually know how to talk to beginners :D.

I will recommend this site to anyone I know!
Comment 13 by Jack http://masters-of-the-void.com/book8.htm#comment13 http://masters-of-the-void.com/book8.htm#comment13 I tried to play around with this by creating a program where I took two passwords from the user and compared them. That worked fine, but I tried to add in a feature so if the passwords didn't match the while loop would restart. This is the code for what I tried to do, and I was wondering why it doesn't work.

#include <stdio.h>
#include <stdbool.h>
#include <string.h>

char userEntry[10];
char userEntry2[10];


int main()
{
bool vRunning;
bool vRestart;
vRunning = true;
vRestart = false;

while( vRunning == true)
{
printf("Please Enter in your desired password\n>");
scanf( "%9s", userEntry);
fpurge( stdin );

printf("Please Enter your desired password again\n>");
scanf( "%9s", userEntry2);
fpurge( stdin );

if( strcmp( userEntry, userEntry2 ) == 0 )
{
printf("The passwords match, your password is now set as %s.", userEntry);
vRestart = false;
vRunning = false;
}
else if( strcmp( userEntry, userEntry2 ) != 0 )
{
printf("These passwords do not match, please re-enter them.");
vRestart = true;
vRunning = false;

}
}

if( vRestart == true)
{
vRunning = true;
}
else
{
printf("\nProgram Quit.");
}

vRunning = false;
printf("\nProgram Quit.");


return 0;
}
Comment 12 by Uli Kusterer http://masters-of-the-void.com/book8.htm#comment12 http://masters-of-the-void.com/book8.htm#comment12 Uli Kusterer writes:
Shadow Luster, if this makes no sense for you, re-read the previous chapters, read other web sites' descriptions of how structs and arrays work in C, and/or ask more questions here or on mailing lists or in forums for people learning C.

I *can* help, but only if you ask questions. "It doesn't make sense to me" is too vague for me. What individual part do you not understand of this chapter, what do you think it says, and why do you think that doesn't make any sense?
Comment 11 by Uli Kusterer http://masters-of-the-void.com/book8.htm#comment11 http://masters-of-the-void.com/book8.htm#comment11 Uli Kusterer writes:
It's nothing in the code that's causing the problem. One of your project settings seems to be wrong. The compiler is telling you that you're building on an Intel Mac (i386/x86_64 are the two kinds of Intel Macs, 32-bit and 64 bits), but trying to run the debugger in PowerPC mode.

Look in the "Project" menu. It has menu items for "Set active architecture" and "Set active executable" and the likes. Try to make sure they all have the same kind of Intel checked that your Mac needs.

Also, make sure you have the newest Xcode. You can't usually use older Xcode versions on newer MacOS X versions. 3.0 is way too old, you should have 3.2.x
Comment 10 by Odikia Irodnar http://masters-of-the-void.com/book8.htm#comment10 http://masters-of-the-void.com/book8.htm#comment10 I'm using Xcode 3.0 on an iMac with Snow Leopard (10.6.4), and every time I try to compile the code you've placed above I get the following message:

"The active architecture ppc is not supported by the debugger for cpu architecture i386/x86_64"

I'm assuming this has something to do with the number of bytes that can be assigned for a given CPU (in my case I think 64 bit/8 bytes). How should the code change?

Thanks for the great tutorial by the way! It's serving as my premier to K&R
Comment 9 by Shadow Luster http://masters-of-the-void.com/book8.htm#comment9 http://masters-of-the-void.com/book8.htm#comment9 Why does this make no sense to me, what should i do if i just don,t get This.
Comment 8 by Uli Kusterer http://masters-of-the-void.com/book8.htm#comment8 http://masters-of-the-void.com/book8.htm#comment8 Uli Kusterer writes:
Amoo, the first is an array of actual characters (for example, a "string", a piece of text). The second one is an array of POINTERS TO characters, or an array of arrays of characters. So, the first one is to hold, for example, one user's name, while the second would be for keeping a list of several users' names.

Does that clarify things?

Also keep in mind that writing char myArray[20] will actually give you not just a variable to hold an address (a pointer), but also the actual memory block the pointer points to. If you just write char* myArray; it would be the same, but would NOT actually create the memory pointed to. It is just a place to store the address of a memory block.

That's not a problem with parameters to functions, as those would get the value from whoever called them anyway. But for a local variable, this distinction is important.
Comment 7 by Amoo http://masters-of-the-void.com/book8.htm#comment7 http://masters-of-the-void.com/book8.htm#comment7 So I am confused. If any array is a pointer, what is the difference between:

char myArray[20];

and

char* myArray[20]

?

aren't they the same thing?
Comment 6 by cMacRun http://masters-of-the-void.com/book8.htm#comment6 http://masters-of-the-void.com/book8.htm#comment6 Richard,

I typed in your code for practice, but I got a "syntax error before 'char'" error message. What did you change from the above code to make it work?
Comment 5 by Richard Howell http://masters-of-the-void.com/book8.htm#comment5 http://masters-of-the-void.com/book8.htm#comment5 Sorry. A silly mistake, and I fixed it now. Thanks anyway.
Comment 4 by Richard Howell http://masters-of-the-void.com/book8.htm#comment4 http://masters-of-the-void.com/book8.htm#comment4 I typed in the above code, and found out that I dont quite know the syntax to make it work..can you help?
Comment 3 by Richard Howell http://masters-of-the-void.com/book8.htm#comment3 http://masters-of-the-void.com/book8.htm#comment3 #include <stdio.h>
#include <stdlib.h>
#include <string.h>


char userEntry[10];
char secUserEntry[10];

int main (int argc, const char * argv[])
{

printf("First of all, enter a name for me to store as a string > ");
scanf("%11s", userEntry);
fpurge(stdin);

printf("User entered : %s", userEntry);

printf("Now, enter a second name for me to compare with the first > ");
scanf("%11s",secUserEntry);
fpurge(stdin);

if (strcmp(char * userEntry, char * secUserEntry) == 0)
{
printf("\nThe two are identical, %11s = %11s", userEntry, secUserEntry);
}
else
{
printf("\nThe two are not idntical, %11s != %11s", userEntry, secUserEntry);
}

return 0;
}
Comment 2 by Luka M http://masters-of-the-void.com/book8.htm#comment2 http://masters-of-the-void.com/book8.htm#comment2 Luka M writes:
Thanks a lot for putting these pages up for free, helped me a lot, and quickly too!
Comment 1 by Bruno Gätjens González http://masters-of-the-void.com/book8.htm#comment1 http://masters-of-the-void.com/book8.htm#comment1 All is very clear!!! Thanks for the explanation :)