I have to write a program for school that opens a file, reads in the first 50 words of a paragraph into an array, then print the words to an output file. Everything appears to be working, but when I view the output file it is nothing but garbage! Can someone please help me? Here is what i have so far:
#include <stdio.h>
void main()
{
char infile[81];
char outfile[81];
char word[50][20];
int i,j;
FILE *fin, *fout;
printf("\n Enter a input file name.");
gets(infile);
fin=fopen(infile,"r");
printf("\n Enter the name of the out file.");
gets(outfile);
fout=fopen(outfile,"w");
if (fin!=NULL)
{
if (fout!=NULL)
{
for(i=0;i<50;i++)
{
for(j=0;j<20;j++)
{
word[i][j]=0;
}
}
for(i=0;i<50;i++)
{
for(j=0;j<20;j++)
{
fscanf(fin, "%s", &word[i][j]);
}
}
for(i=0;i<50;i++)
{
for(j=0;j<20;j++)
{
fprintf(fout, "%s", word[i][j]);
}
fprintf(fout, "\n");
}
}
else
{
printf("\n Error opening the output file!");
printf("\n The program will end now!");
}
}
else
{
printf("\n Error opening the input file!");
printf("\n The program will end now!");
}
}
Thanks in advance!!