Coding Discussions
Would you like to react to this message? Create an account in a few clicks or log in to continue.

please check the error and correct the program

3 posters

Go down

please check the error and correct the program Empty Re: please check the error and correct the program

Post by Prateek Gupta Thu Apr 06, 2017 11:37 pm

I have just kept your getc() functions in the loop condition so that it continuously takes input and not once as it was taking previously in your given program

#include <stdio.h>
void main()
{
FILE *fp,*fp1,*fp2;

fp=fopen("F://emp.txt","w");
fp1=fopen("F://a.txt","r");
fp2=fopen("F://a1.txt","r");
char ch1,ch2;

while((ch1=getc(fp1))!=EOF&&(ch2=getc(fp2))!=EOF)
{
while(ch1!='\n'&&ch1!=EOF)
{
putc(ch1,fp);
ch1=getc(fp1);
}
putc('\n',fp);
while(ch2!='\n'&&ch2!=EOF)
{
putc(ch2,fp);
ch2=getc(fp2);
}
putc('\n',fp);
}
fclose(fp);
fclose(fp1);
fclose(fp2);
}

Prateek Gupta
Admin

Posts : 6
Join date : 2017-04-04

https://clanofcoders.board-directory.net

Back to top Go down

please check the error and correct the program Empty Re: please check the error and correct the program

Post by akarshsomani Fri Apr 07, 2017 12:31 pm

it is not giving the correct answer.please code,compile,run and check..

akarshsomani

Posts : 21
Join date : 2017-04-04

Back to top Go down

please check the error and correct the program Empty This Program is almost working fine

Post by iamdsc_0410 Tue Apr 11, 2017 7:07 pm

//merging lines of two files
//make two files named emp.doc and emp1.doc
#include<stdio.h>
int main()
{
FILE *fp,*fp1;
char c,c1;
int i=0,j=0;
while((c!=EOF)||(c1!=EOF))
{
c='\0';
fp=fopen("emp.doc","r");
fseek(fp,i,SEEK_SET);
while(c!='\n'&&c!=EOF)
{
c=getc(fp);
i++;
putchar(c);
}
fclose(fp);
c1='\0';
fp1=fopen("emp1.doc","r");
fseek(fp,j,SEEK_SET);
while(c1!='\n'&&c1!=EOF)
{
c1=getc(fp1);
j++;
putchar(c1);
}
fclose(fp1);
}
return 0;
}
iamdsc_0410
iamdsc_0410

Posts : 14
Join date : 2017-04-11
Age : 26
Location : IIIT Kalyani

Back to top Go down

please check the error and correct the program Empty you have to save the alternate lines in the third file instead of direct printing.

Post by akarshsomani Tue Apr 11, 2017 10:07 pm

iamdsc_0410 wrote://merging lines of two files
//make two files named emp.doc and emp1.doc
#include<stdio.h>
int main()
{
FILE *fp,*fp1;
char c,c1;
int i=0,j=0;
while((c!=EOF)||(c1!=EOF))
{
c='\0';
fp=fopen("emp.doc","r");
fseek(fp,i,SEEK_SET);
while(c!='\n'&&c!=EOF)
{
c=getc(fp);
i++;
putchar(c);
}
fclose(fp);
c1='\0';
fp1=fopen("emp1.doc","r");
fseek(fp,j,SEEK_SET);
while(c1!='\n'&&c1!=EOF)
{
c1=getc(fp1);
j++;
putchar(c1);
}
fclose(fp1);
}
return 0;
}

akarshsomani

Posts : 21
Join date : 2017-04-04

Back to top Go down

please check the error and correct the program Empty Re: please check the error and correct the program

Post by iamdsc_0410 Tue Apr 11, 2017 10:12 pm

Read the question again!
But storing in a third file can also be done just that will make the code longer and complex
iamdsc_0410
iamdsc_0410

Posts : 14
Join date : 2017-04-11
Age : 26
Location : IIIT Kalyani

Back to top Go down

please check the error and correct the program Empty Re: please check the error and correct the program

Post by akarshsomani Tue Apr 11, 2017 10:23 pm

check my code(first comment in this question).please tell me the error.

akarshsomani

Posts : 21
Join date : 2017-04-04

Back to top Go down

please check the error and correct the program Empty Re: please check the error and correct the program

Post by iamdsc_0410 Tue Apr 11, 2017 10:33 pm

We will discuss the errors later when we meet !!
iamdsc_0410
iamdsc_0410

Posts : 14
Join date : 2017-04-11
Age : 26
Location : IIIT Kalyani

Back to top Go down

please check the error and correct the program Empty Re: please check the error and correct the program

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum