#include<stdio.h>
#include<ctype.h>
#define null 0
main()
{
char ch;
FILE *fp;
FILE *p;
clrscr();
fp=fopen("alpha.txt","w");
if(fp==null)
{
exit();
}
else
{
printf("Enter th data and press ^z : ");
while((ch=getchar())!=EOF)
{
putc(ch,fp);
}
fclose(fp);
}
fp=fopen("alpha.txt","r");
p=fopen("beta.txt","w");
while((ch=getc(fp))!=EOF)
{
if(islower(ch))
{
putc(toupper(ch),p);
}
else
{
putc(tolower(ch),p);
}
}
fclose(fp);
fclose(p);
fp=fopen("beta.txt","r");
if(fp==null)
{
printf(":(/>");
exit();
}
else
{
while((ch=getc(p))!=EOF)
{
putchar(ch);//not working
}
fclose(p);
}
getch();
}
problem i face is that putchar() not working
Page 1 of 13 Replies - 160 Views - Last Post: 03 November 2011 - 07:00 PM
#1
problem i face is that putchar() not working
Posted 03 November 2011 - 04:31 PM
Replies To: problem i face is that putchar() not working
#2
Re: problem i face is that putchar() not working
Posted 03 November 2011 - 05:37 PM
putchar(char) writes to stdout, so if your expecting data to be put in the file it won't be there. Also, look at this code:
Your calling getc(p) on a closed file.
fclose(p); //HERE!!
fp=fopen("beta.txt","r");
if(fp==null)
{
printf(":(/>");
exit();
}
else
{
while((ch=getc(p))!=EOF) //HERE!!
{
putchar(ch);//not working
}
fclose(p);
}
Your calling getc(p) on a closed file.
This post has been edited by blackcompe: 03 November 2011 - 05:39 PM
#3
Re: problem i face is that putchar() not working
Posted 03 November 2011 - 06:00 PM
blackcompe, on 03 November 2011 - 05:37 PM, said:
putchar(char) writes to stdout, so if your expecting data to be put in the file it won't be there. Also, look at this code:
Your calling getc(p) on a closed file.
fclose(p); //HERE!!
fp=fopen("beta.txt","r");
if(fp==null)
{
printf(":(/>");
exit();
}
else
{
while((ch=getc(p))!=EOF) //HERE!!
{
putchar(ch);//not working
}
fclose(p);
}
Your calling getc(p) on a closed file.
what is stdout?
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|