Mail Archives: djgpp/1997/04/02/01:28:07
Deltaman wrote:
> =
> I have a program to exchange special HTML-letters to plain text i.e
> é to =E9=82 and so on.
> =
> In the beginner I set a string called 'test_string'
> =
> char test_string[5] ;
This is too short. This allocates space for five characters, but you
must also account for the null character ('\0') that terminates all
strings in C. "#197;" is SIX characters, not five. "#197; " is seven
characters. Consider yourself lucky if such bugs don't crash your
programs.
> When I checks if test_string is equal to a special character:
> =
> if (test_string =3D=3D "#197; ") printf("I should see this");
> if (test_string =3D=3D "#197;") printf("or this");
This is not how strings are compared in C. You must use the strcmp()
library function, like so:
if ( strcmp( test_string, "#197; " ) =3D=3D 0 ) printf( "I should see thi=
s"
);
if ( strcmp( test_string, "#197;" =3D=3D 0 ) printf( "or this" );
These are all extremely basic questions about the C language itself. =
While we are happy to help you out here, this newsgroup is primarily a
forum for djgpp-specific questions, not basic programming questions. I
recommend that you curl up with a good C book, such as The Waite Group's
_New C Primer Plus_, or the Kernighan and Ritchie book whose name I can
never remember. ;) C is not Pascal, nor is it BASIC, and making such
assumptions can get you into lots of trouble.
-- =
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | fighteer AT cs DOT com |
| "Starting flamewars since 1993" | http://www.cs.com/fighteer |
| *** NOTICE *** This .signature is generated randomly. |
| If you don't like it, sue my computer. |
---------------------------------------------------------------------
- Raw text -