Q : Write a ‘C’ program to print only first 12 characters including blank space from file test.txt.
Solution :
Solution :
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *pt;
int i;
char ch;
pt=fopen("test.txt","r");
if(pt==NULL)
printf("\n\tUnable
to open file for read");
else
{
i=1;
while(1)
{
ch=getc(pt);
printf("%c",ch);
i++;
if(i>12)
break;
}
fclose(pt);
}
}
No comments:
Post a Comment