Question:28
Write a C program to read a file line by line, display lines which are starting with ‘a’ or ‘A’.
Note:
The above program can be modified to display lines starting from any character
Sol:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
FILE *fp;
char buff[255];
fp = fopen("test11.txt", "r");
if(fp==NULL)
{
printf("Unable to open the file\n");
return(0);
}
while(1)
{
fgets(buff, 255,fp); //reads line by line
if(feof(fp))
{
printf("\n\n\nend of file");
break;
}
if(buff[0]=='a' || buff[0]=='A')
printf("%s\n", buff );
}
fclose(fp);
getch();
return(0);
}
Question:29
Write a C program to read a file line by line, display lines which are starting with vowels (aeiouAEIOU)
Note:
The above program can be modified to display lines starting from any character
Sol:
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
FILE *fp;
char buff[255];
fp = fopen("test11.txt", "r");
if(fp==NULL)
{
printf("Unable to open the file\n");
return(0);
}
while(1)
{
fgets(buff, 255,fp); //reads line by line
if(feof(fp))
{
printf("\n\n\nend of file");
break;
}
if(buff[0]=='a' || buff[0]=='A' || buff[0]=='e' || buff[0]=='E' || buff[0]=='i' ||
buff[0]=='I' || buff[0]=='o' || buff[0]=='O' || buff[0]=='u' || buff[0]=='U')
printf("%s\n", buff );
}
fclose(fp);
getch();
return(0);
}




