Mail Archives: djgpp/1999/11/11/17:01:30
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 <conio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
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<strlength; i++)
{
t1 = string[i]; -- error here if first error
bypassed
for (int j=i; j<strlength; j++) // scan to end
{
if (string[j] == t1) // match!
{
printf("%s\n", "match !");
}
}
}
}
void main()
{
getstring();
scanstring();
getch();
}
mariusm AT parys DOT lia DOT net
- Raw text -