Hi friends,
I am stuck with little problem, the program reads a file and stores
in str1, then I put a loop that extracts 4 words at time by using a counter, thanks to Mr.nutshell who gave me a hint how to read in 4 word at a time, then the program stores the extracted 4 words int an array called pboxOut .. and then a function b_pox is called which swaps the two middle characters and finally the function return is read to file called outfile
The problem is that the output is written to the file but strange
characters are put at the back of the string written to the file.
I am using fputs to write to a file.
can anyone see what may be the cause of this strange characters at the back of thr string.
Code:
code
#define max 1024
char* p_box (char* orig_msg , char* msg_after_pbox ) ;
int main (int argc, char *argv[])
{
FILE *infile, *outfile;
//char ch;
char str1 [max];
char pboxOut [5]; /* temporary for output */
int j,count;
char Temp1[5];
/* start processing the file */
while( fgets(str1,max,infile) != NULL )
{
count = 0;
for (j = 0 ; j < max; j++)
{
/* if count = 4, we already have letters,start processing */
if (count % 4 == 0)
{
/* check if what read is character */
if (isalpha(str1[j]))
Temp1 [0] = str1[ j ];
Temp1 [1] = str1[ j + 1];
Temp1 [2] = str1[ j + 2];
Temp1 [3] = str1[ j + 3];
Temp1 [4] = '\0';
p_box( Temp1, pboxOut );
fputs(pboxOut,outfile);
//fprintf(outfile,pboxOut);
count = 0;
}
count++;
}
}