write a function in c A concordance is a list of words appearing in a body of te
ID: 3760352 • Letter: W
Question
write a function in c
A concordance is a list of words appearing in a body of text. The list of words includes only ''truc'' words, consisting entirely of alphabctic characters, after all punctuation and whitespace characters have been discarded. Write a C99 function, with the prototype: char **concordance(char *fjlename mt *nwords); to build a concordance from a named text tile. The first parameter, filename, provides the name of the text file containing the words. You may assume that the text file contains only alphabetic, punctuation, and whitespace characters. The second parameter, nwords, provides a pointer to an integer. On successful return from the function, the integer pointed to by nwords will contain the number of distinct words found in the file. On successful return, concordance will return a vector of strings, containing the distinct words found in the text tile. If any problems are detected during the execution of concordance, the function should return the NULL pointer.Explanation / Answer
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#define true 1
#define false 0
typedef struct numbernode
{
int number;
struct numbernode *link;
}
numbernode;
typedef struct wordnode
{
char *word;
numbernode *numberhead;
numbernode *numbertail;
struct wordnode *link;
} wordnode;
wordnode *concordance = NULL;
int getword(char *w) {
char c;
while ((c=getchar()) != EOF && !isalpha(c));
if (c==EOF)
return false;
else {
*w++ = tolower(c);
while ((c=getchar()) != EOF && isalpha(c))
*w++ = tolower(c);
*w = '';
return true;
} // if/else
} // getword
wordnode *makewordnode (char *w) {
wordnode *temp;
temp = (wordnode *) malloc(sizeof(wordnode));
temp->link = NULL;
temp->numberhead = NULL;
temp->numbertail = NULL;
temp->word = (char*) malloc(strlen(w));
strcpy(temp->word,w);
return temp;
} // makewordnode
wordnode *findword(char *wordbuffer) {
}
numbernode *makenumbernode(int n) {
} // makenumbernode
void insertnumber(wordnode *w, int n) {
if (w->numberhead) {
w->numbertail->link = makenumbernode(n);
w->numbertail = w->numbertail->link;
}
else
w->numberhead = w->numbertail = makenumbernode(n);
}
void printword(wordnode *w)
{
numbernode *n;
printf("%s", w->word);
for (n=w->numberhead; n; n=n->link)
printf(" %d", n->number);
printf(" ");
}
void printconcordance(void)
{
wordnode *w;
for (w=concordance; w; w=w->link)
printword(w);
}
int main(void)
{
char wordbuffer[80];
int wordnumber = 0;
printf(" Here is the concordance for your text. ");
printconcordance();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.