#include <stdio.h>
#include <stdlib.h>
int CountWords (FILE *p)
{
int countWords=0;
char c=fgetc(p);
while (c!=EOF)
{
if (c=='\n')
countWords++;
c=fgetc(p);
}
countWords++; /*EOF means another word has ended*/
return countWords;
}
int GetWordLength (FILE *p)
{
int length=0;
char c=fgetc(p);
while (c!='\n' || c!=EOF)
{
length++;
}
length++; /*the charectar '\0' takes a place in the word's array*/
return length;
}
void GetWord (FILE *fp,char p[],int arrayLength)
{
int i;
char extraChar;
for (i=0;i<arrayLength-1;i++)
p[i]=fgetc(fp);
extraChar=fgetc(fp); /*to get rid of the extra '\n' charectar*/
}
/*int EditDistance (char a[],char b[],int aLength,int bLength)
{
int i,j,cost;
int d[aLength+1][bLength+1];
if (aLength==0)
return bLength;
if (bLength==0)
return aLength;
for (j=0;j<bLength;j++)
d[0][j]=j;
for (i=0;i<aLength;i++)
d[i][0]=i;
for (i=1;i<=aLength;i++)
for (1=1;j<=bLength;j++)
{
if (a[i]==t[j])
cost=0;
else
cost=1;
*/
int main (int argc, char *argv[])
{
FILE *pf1;
int countWords,*arrayLengths/*,i,j,temp*/;
char /**p,*/**array;
if (argc!=3)
{
printf ("not the right amount of arguments\n");
exit (1);
}
if ((pf1=fopen(argv[2],"r"))==NULL)
{
printf ("failed to open file\n");
exit (1);
}
countWords=CountWords(pf1);
fclose (pf1);
if ((array=(char **) malloc (countWords*sizeof(char *)))==NULL)
{
printf ("allocation failed\n");
exit (1);
}
if ((arrayLengths=(int *) malloc (countWords*sizeof(int)))==NULL)
{
printf ("allocation failed\n");
exit (1);
}
printf ("program works\n");
return 0;
}