Write a program in ‘C’ language that accepts the name of a file as input and prints those lines of the file which have the word ‘this’. 10m Dec2007

By | June 12, 2015

Write a program in ‘C’ language that accepts the name of a file as input and prints those lines of the file which have the word ‘this’. 10m Dec2007 

 

#include<stdio.h>
void main()
{
FILE *fp;
int cnt=0;
char str[80],lines[400];
clrscr();
if ((fp=fopen(“test.txt”,”r”))== NULL)
{
printf(“File does not exist\n”);
exit(0);
}
while(!(feof(fp)))
{
fgets(str,80,fp);
if(strcmp(“this”,str))
{
fgets(lines,400,fp);
printf(“%s”,lines);
}
}
fclose(fp);
getch();
}

Code:

#include<stdio.h>
void main()
{
FILE *fp;
int cnt=0;
char str[80],lines[400];
clrscr();
if ((fp=fopen("test.txt","r"))== NULL)
{
printf("File does not exist\n");
exit(0);
}
while(!(feof(fp)))
{
fgets(str,80,fp);
if(strcmp("this",str))
{
fgets(lines,400,fp);
printf("%s",lines);
}
}
fclose(fp);
getch();
}

Screen Shots:

C_program_File_Print_Line

C_program_File_Print_Line_Output

 

Write a program in ‘C’ language to convert a decimal number into binary number. 10m Dec2007

 

Similar program can be found on this link http://cssimplified.com/assignments/a-c-program-that-takes-a-decimal-number-and-converts-it-into-binary-octal-and-hexadecimal-equivalents-your-program-should-have-functions-for-each-type-of-conversion-these-functions-should-implement

 

Write a program in ‘C’ language to add two matrices. 10m Dec2007

 

Solved program can be found on this link http://cssimplified.com/c-programming/an-interactive-c-program-to-add-two-matrices-or-subtract-two-matrices