file manipulation

Hi ,
i was trying to write every 3rd character from first file to the second file.
I'm using VS2008.
But i'm getting error in debugger as (stream!=NULL).
here is the code.
#include<stdio.h>
#include<string.h>


int main()
{
FILE *fp=NULL,*fp1=NULL;
int count =0;
char ch;
if(fp=fopen("s1.txt","r")==NULL)
{
printf("error\n");
}
if(fp1=fopen("s2.txt","w")==NULL)
{
printf("error\n");
}
while((ch=getc(fp))!= EOF)
{

if(++count%3==0)
{
putc(ch,fp1);
}
}
return 0;
}
1)if((fp=fopen("s1.txt","r"))==NULL)
2)if((fp1=fopen("s2.txt","w"))==NULL)
3)s1.txt must be present.
4)It will not read 1st character.(It starts reading from 3)

It worked for me with these things.
hi Akshit,
Thanks for the reply
s1.txt was present.
just by including fp=fopen("s1.txt","r") within an extra bracket solved the problem for me.. its a kind of strange. but it works now.

Thanks once again.
Happy to help.
Topic archived. No new replies allowed.