Need some help here please!

Mar 13, 2011 at 4:27pm
Can someone explain to me, what is wrong about this code:

char astring[10];
int i = 0;
/* Using scanf isn't really the best way to do this; we'll talk about that
in the next tutorial, on strings */
scanf( "%s", astring );
for ( i = 0; i < 10; ++i )
{
if ( astring[i] == 'a' )
{
printf( "You entered an a!n" );
}
}

I am going wrong at a couple points, I just don't understand the errors...

And could someone please tell me where exactely a syntax goes, or what a syntax is?
Mar 13, 2011 at 4:30pm
It would really help if you posted the compiler errors, we are no magicians. The code is ok but it doesn't work if you didn't include cstdio at the top.
Mar 13, 2011 at 4:36pm
line 5: error: expected initializer before 'char'
first error is line 9: Error: expected constructor, destructor, or type conversion before '(' token
line 11: error: expected unqualified-id before 'for'
line 11: error:expected constructor, destructor, or typ conversion before '<' token
line 11: error: expected unqualified-id before '++' token
Last edited on Mar 13, 2011 at 4:37pm
Topic archived. No new replies allowed.