hi guys i need help. In fact it's an assignment. I'm fed up with this stuff. This is my code. has got many errors. actually it's just messy. please provide me with me a code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define MAXWORDS 5000 /* max no of word that can be read */
#define MAXLEN 25 /* max word length */
char *lines[MAXWORDS]; /* pointers to lines of text */
int freq[MAXWORDS] = {0};
bool is_present(char *lines[], int line_cnt);
int get_word(char *, int); /* pointer to a single line of text */
int read_lines(char *lines[], int line_cnt);
void write_words(char *lines[], int line_cnt);
int main(void)
{
FILE *fs;
int line_cnt; /* no of lines read */
if (fs = (fopen(/home/gamo/Downloads/shakespeare.txt, "rb")) == NULL) {
fprintf(stderr, "no source file");
exit(0);
}
else if ((line_cnt = read_lines(lines, MAXWORDS)) >= 0) /* was read successfully */
write_words(lines, line_cnt);
else
printf("Error: Input too big\n");
}
int read_lines(char *lines[], int maxlines) {
int len; /* length of current line */
int line_cnt = 0; /* no of lines read */
char line[MAXLEN]; /* line will hold the line read */
char *p;
while ((len = get_word(line, MAXLEN)) > 0)
/* signal error if line_cnt > MAXLINES or system runs out of memory for array*/
if ((line_cnt >= maxlines) || (p = malloc(len * sizeof(char))) == NULL)
return -1;
else if(is_present) ;
else if(!is_present) {
strcpy(p, line); /* copy line into allocated space */
lines[line_cnt++] = p; /* place pointer to line in array */
freq[line_cnt]++;
}
return line_cnt;
}
void write_words(char *lines[], int line_cnt) {
int i;
for (i = 0; i < line_cnt; i++)
printf("%s\n", lines[i]);
}
int get_word(char line[],int maxline) {
int c, i;
for (i = 0; (i < maxline - 1) && ((c = getc(fs)) != EOF) && (c != '\n') && (c != ' ') && (c != '\t'); ++i)
line[i] = c;
if (c == '\n')
line[i++] = c;
line[i] = 0;
return i; /* return line length */
}
bool is_present(char *lines[], int line_cnt)
{
int i;
for (i = 0; i < line_cnt; i++)
if (strcmp(p , lines[i]) == 0) {
++freq[i];
return true;
}
else
return false;
}