X-ROUTED: Thu, 11 Nov 1999 18:36:14 -0500 Message-ID: <382B520C.2AEC917E@greenbelt.com> Date: Thu, 11 Nov 1999 18:32:28 -0500 From: Ed James Organization: GIAC X-Mailer: Mozilla 4.51 [en] (WinNT; I) X-Accept-Language: en MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: Re: Please help References: <0FL100CMRYY7ZI AT cpt-proxy1 DOT mweb DOT co DOT za> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com one problem, when you use 'char *string", you define a pointer to a character, but you don't actually allocate any space for the string. Try replacing it with 'char string[80]' and see if that helps. Actually, it's prolly better to use a name like 'InStr' or 'tempStr', etc instead of 'string' which is a likely candidate for being a reserved word with some languages. Also, since string is now an array, in your scanf, you won't need the '&' now. Marius Myburg wrote: > Can anyone please tell me why this program doesn't want to work? It > compiler fine, but when I run it, after I have entered the requested text, > it returns with an error at the strlength=strlen(string) line. Also, when > I remove that line, set string length to say 8 and enter a 8-character > string, it returns with an error when I want to access the string's > individual characters, at t1 = string[i]. > > #include > #include > #include > #include > > char *string; > int strlength; > > void getstring() > { > clrscr(); > printf("%s", "Enter a string > "); > scanf("%s", &string); > printf("%s", &string); > strlength = strlen(string); -- error here > }; > > int scanstring() > { > char t1; // temp char > > for (int i=0; i { > t1 = string[i]; -- error here if first error > bypassed > for (int j=i; j { > if (string[j] == t1) // match! > { > printf("%s\n", "match !"); > } > } > } > } > > void main() > { > getstring(); > scanstring(); > getch(); > } > > mariusm AT parys DOT lia DOT net