cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/11/17:01:30

Date: Thu, 11 Nov 1999 23:44:31 +0200
From: Marius Myburg <iti06469 AT mweb DOT co DOT za>
Subject: Please help
To: djgpp AT delorie DOT com
Message-id: <0FL100CMRYY7ZI@cpt-proxy1.mweb.co.za>
MIME-version: 1.0
X-Mailer: Microsoft Internet Mail 4.70.1154
X-MSMail-Priority: Normal
X-Priority: 3
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019