im trying to scan words from a file into an array of strings.
i dont understand why the compiler giving me this warning:
t2.c: In function ‘get_words’:
t2.c:12:27: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat=]
while(fscanf(stream,"%s",neword[j])!=EOF);
~^ ~~~~~~~~~
t2.c:14:22: warning: comparison between pointer and integer
if(neword[j] == ":" || neword[j] == "\n")
^~
t2.c:14:42: warning: comparison between pointer and integer
if(neword[j] == ":" || neword[j] == "\n")
^~
t2.c:17:21: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
words[i]=*neword;
^
t2.c: In function ‘main’:
t2.c:42:5: warning: attempt to free a non-heap object ‘d_words’ [-Wfree-nonheap-object]
free(d_words);
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 100
#define WORD_L 20
void get_words(FILE *stream, char *words[])
{
int i=0, j=0;
char neword[WORD_L];
while(fscanf(stream,"%s",neword[j])!=EOF);
{
if(neword[j] == ":" || neword[j] == "\n")
{
words[i]=(char*)malloc((j+1)*sizeof(char));
words[i]=*neword;
i++;
printf("%s", words[i]);
}
printf("%s\n", neword);
j++;
}
}
int main()
{
FILE *story, *dictionary, *new_story;
char *d_words[N], *s_words[N];
char *p_story, *p_diction, *p_rewrite;
story=fopen("story.txt","r");
dictionary=fopen("dictionary.txt","r");
new_story=fopen("new_story.txt","w");
if(story==NULL || dictionary==NULL || new_story==NULL)
{
printf("can't open input file!\n");
exit(1);
}
get_words(dictionary, d_words);
free(d_words);
return 0;
}
a little background ... i need to replace some incorrect words from a story.. i have dictionary for it..
please help..
thank you