I got it to work like this, but it's really yucky and unsafe and all kinds of nasty stuff that you can imagine :-)
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i;
int count;
char next_char;
char array[10000];
FILE *dictfile, *wordfile;
if ((dictfile = fopen("input.txt", "r"))==NULL) {
printf("Cannot open this file\n");
exit(1);
}
while(!feof(dictfile)) {
next_char = 0;
count=0;
for (i=0; next_char!='\n' && next_char != EOF; i++) { /* read one line in */
if (fscanf(dictfile, "%c", &next_char) != 1)
{
break;
}
array[i] = next_char;
count++;
}
//printf("count is %d\n", count);
wordfile = stdout;
if ((array[count - 2] == 'n') && (array[count - 3] == 'a')
&& (array[count - 4] == 'm'))
{
for(i=0; i<count; i++)
{
fprintf(wordfile, "%c", array[i]);
}
}
printf("\n");
}
fclose(dictfile);
return 0;
}
This way would be way better :-)
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
char array[10000];
FILE *dictfile, *wordfile = stdout;
if ((dictfile = fopen("input.txt", "r")) == 0)
{
return 1;
}
while(fgets(array, sizeof array, dictfile) != 0)
{
if (strstr(array, "man") != 0)
{
fprintf(wordfile, "%s", array);
}
}
fclose(dictfile);
return 0;
}