Archived

This topic is now archived and is closed to further replies.

RegularKid

Sorry, but I need just a little more help...

Recommended Posts

RegularKid    139
Ok. Here is what I have so far for my font engine (of course I''m going to change the printf with bitmap drawing routines...but this is just for testing it in dos mode). But when i compile and run it i get this: A A A A A A A A What am I doing wrong?! Here is the code... #include #include #include #include void PrintMessage(char *mytext) { int length = strlen(mytext); for(int i = 0; i < length; i++) { if(mytext = ''A'') { printf("A\n"); } else if(mytext[i] = ''B'') { printf("B\n"); } } } void main( void ) { PrintMessage("ABBAABAB"); } Any help would be great. thanks.

Share this post


Link to post
Share on other sites
Esap1    122
Well, I think its when you do:
if(mytext = ''A'')
{
printf("A\n");
}
else if(mytext = ''B'')
{
printf("B\n");
}

It should be
if(mytext[i] = ''A'') //See the diff
{
printf("A\n");
}
else if(mytext[i] = ''B'')
{
printf("B\n");
}


PS: Why would you do that?, also, you could of done a switch, doesnt matter though.

Share this post


Link to post
Share on other sites
Dave_Hunt    122
RegularKid,

Two things:

First, your first ''if'' is missing the subscript from mytext.

Second, both ''if''s have ''='' (assignment) instead of ''=='' (equality). So, you''re always going to get a TRUE (non-zero) result from the first ''if'' and, therefore, always print an ''A''.

Dave

Share this post


Link to post
Share on other sites