Good day.
I need help on a program that I'm working on.
It's supposed to take the strings in input.txt and put the odd numbered lines to odd.txt and the even ones to even.txt.
here's the code I have made so far...
#include<stdio.h>
#include<stdlib.h>
#define p printf
#define s scanf
int main (int argc, char *argv[])
{
FILE *fptr1, *fptr2, *fptr3;
int count = 0;
char check[256];
char temp[256];
fptr1=fopen("input.txt", "r");
fptr2=fopen("Odd.txt", "w");
fptr3=fopen("Even.txt", "w");
while (fgets(temp, sizeof(temp), fptr1) != NULL)
{
fscanf(fptr1, "%s", &check);
if (check != "\n")
{
if (count==1)
{
fputs(check,fptr2);//put first line in odd.txt
}
else if(count%2==1)
{
fputs(check,fptr2);//odd
}
else
{
fputs(check,fptr3);//even
}
}
count+=1;
}
fclose(fptr1);
fclose(fptr2);
fclose(fptr3);
p("Finished processing the file...\n\n");
system("PAUSE");
return 0;
}
The problem is that the first line should be in Odd.txt since it's line # 1 but it doesn't show.
I hope you guys could help me. thank you in advance!