Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Imladris improvement algorithm-compname()

Posted on 2001-06-05
2
Medium Priority
?
208 Views
Last Modified: 2010-04-15
Dear imladris,

as the first question of mine if you could stil remember :
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=cprog&qid=10345372
I would like to improve and make a few changes..
my requirement is to change this program into the last one you made for me...

compare name with datafile (names.dat) and then print the name matches and then return  number of matched names...get ird of the output header and all information like death date, marriage, last name , first name..only keep name  to compare with datafile...(anyway you would understand this easily since it's eaxtly the same requirements as you have done be4)

many thanks,
Korsila

p.s. I need to think for a good requirement to challenge your skill :) and i would be deluighted if you coud move your position of expert to second  ^_^
hope to see your pix one day wining expert of the month heheheh


0
Comment
Question by:korsila
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 200 total points
ID: 6162416
This should do it:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int compname(char *,char *);
int compchar(char a,char b);
void getinput(char *prompt,char n[]);

void main(int argc,char *argv[])
{   int matched,msave,usave,mc;
  char name[150],line[500];
  float LIG;
  FILE *namefile,*mfile,*ufile;

  printf("Save matched names in matched.dat (y or n)?\n");
  gets(line);
  msave=(toupper(line[0])=='Y');
  printf("Save unmatched names in unmatched.dat (y or n)?\n");
  gets(line);
  usave=(toupper(line[0])=='Y');
  namefile=fopen("names.dat","r+"); //open file in read/write mode
  if(msave)mfile=fopen("matched.dat","w");
  if(usave)ufile=fopen("unmatched.dat","w");
  do
  {   printf("Please enter name to match:\n");
      gets(name);
      fseek(namefile,0L,0); //seek to start of file
      matched=0;
      mc=0;
      while(fgets(line,500,namefile)!=NULL)
      {   line[strlen(line)-1]='\0';
          if(compname(name,line))
          {    printf("%s\n",line);
               ++mc;
               if(msave)
               {   if(matched==0)fprintf(mfile,"Match name %s\n",name);
                   fprintf(mfile,"%s\n",line);
               }
               matched=1;
          }
      }
      if(matched==1)
       {   if(msave)fprintf(mfile,"----------------------------------------\n");
           printf("Number of Matches: %d\n",mc);
       }
      else
      {   printf("No Matches Found.\n");
          if(usave)
          {   fprintf(ufile,"Match name %s\n",name);
              fprintf(ufile,"No Matches found\n");
              fprintf(ufile,"--------------------\n");
          }
      }
      printf("Compare again (y or n)?\n");
      gets(line);
  } while(toupper(line[0])=='Y');
  fclose(namefile);
  if(msave)fclose(mfile);
  if(usave)fclose(ufile);
}

int compname(char *nm1,char *nm2)
{   int i,l1,l2;

   l1=strlen(nm1);
   l2=strlen(nm2);
   for(i=0; i<l1; ++i)
   {   if(i<l2 && compchar(nm1[i],nm2[i]))continue;
       if(i+1<l2 && compchar(nm1[i],nm2[i+1]))continue;
       if(i+2<l2 && compchar(nm1[i],nm2[i+2]))continue;
       if(i-1<l2 && i>0 && compchar(nm1[i],nm2[i-1]))continue;
       if(i<l2 && i>0 && compchar(nm1[i-1],nm2[i]))continue;
       if(i+1<l1 && i<l2 && compchar(nm1[i+1],nm2[i]))continue;
       if(i+2<l1 && i<l2 && compchar(nm1[i+2],nm2[i]))continue;
       if(i+1<l1 && i+1<l2 && compchar(nm1[i+1],nm2[i+1]))continue;
       if(i+2<l1 && i+2<l2 && compchar(nm1[i+2],nm2[i+2]))continue;
       return(0);
   }
   return(1);
}

int compchar(char a,char b)
{     return(toupper(a)==toupper(b));
}


// prompt user for input
// get input
// copy it safely into provided variable

void getinput(char *prompt,char n[])
{   char ipc[150];

  printf("%s:\n",prompt);
  gets(ipc);
  strncpy(n,ipc,19);
  n[19]='\0';
  return;
}
0
 

Author Comment

by:korsila
ID: 6164122
thanks...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question