Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int binarysearch (char [], int, char [], int);
main ()
{
char cum_nouns [700] [21];
int file_len=0;
char noun [6] [21];
int count;
int location;
char yes_or_no [12];
int yes;
int no;
int length;
char username [6];
char filename [256];
char filename1 [256];
char filename2 [256];
char filename3 [500];
char filename4 [256];
char filename5 [256];
char file6suffixes [256];
char file7possessivepronouns [256];
char file_twowordverbs[256];
char file_secondpartoftwv [256];
char filetwowordverbspt [256];
int temp;
int file_len;
FILE * outfile;
FILE * outfilef;
FILE * infile;
FILE * infilev;
printf ("Hi, Please type in your user name in lowercase letters only.\n");
scanf ("%s", username);
length = strlen (username);
strncpy (filename, username, length);
printf ("Hi. Using this program, you'll enter all of the new words you taught your \nstudents today.\n\n");
printf ("We'll start with nouns. Did you learn any new nouns today?\n\n");
printf ("Type yes or no. Use lowercase only.\n");
scanf ("%s", & yes_or_no) ;
yes = strcmp ("yes", yes_or_no);
no = strcmp ("no", yes_or_no);
if ((yes !=0) && (no !=0)) {
printf ("\n\nERROR. Please enter yes or no in lowercase.\n");
scanf ("%s", & yes_or_no);
yes = strcmp ("yes", yes_or_no);
no = strcmp ("no", yes_or_no);
}
strncpy (filename, username, length);
strcat (filename, "nouns.txt");
outfile = fopen (filename, "a");
for (count = 0; no !=0; count = count + 1) {
temp = count + 1 ;
printf ("\nplease enter noun %d\n", temp);
scanf ("%s", & noun [count]);
fprintf (outfile, "%s ", noun [count]);
printf ("\n\nDo you want to enter another noun?");
printf (" Enter yes or no.\n Use lowercase only.\n");
scanf ("%s", & yes_or_no);
yes = strcmp ("yes", yes_or_no);
no = strcmp ("no", yes_or_no);
if ((yes !=0) && (no !=0)) {
printf ("\nERROR. Please enter yes or no in lowercase only.\n");
scanf ("%s", & yes_or_no);
yes = strcmp ("yes", yes_or_no);
no = strcmp ("no", yes_or_no);
}
}
fclose (outfile);
strncpy (filename4, username, length);
strcat (filename4, "worksheet.txt");
infile = fopen (filename, "r");
outfile = fopen (filename4, "a");
for (i = 1; i < file_len +1; i ++){
fscanf (infile, "%s", & cum_nouns [i]);
fprintf (outfile, "%s\n\n\n", cum_nouns[i]);
}
fclose (infile);
fclose (outfile);
location=binarysearch(cum_nouns [i] , file_len, noun[count], count);
}
int binarysearch (char data [], int n, char newitem [], int datapositionofnewitem)
{
int low, high, test, findnewitem;
low=0;
high=n-1;
while (low<=high){
test=(low +high/2);
findnewitem=strcmp (newitem[datapositionofnewitem], data[test]);
if(findnewitem==0)
return test;
else if (findnewitem<0)
high = test -1;
else
low=test+1;
}
return -1;
}