Tuesday 22 August 2017

Print Some Character from a File

Q : Write a ‘C’ program to print only first 12 characters including blank space from file test.txt.
Solution :

#include<stdio.h>
#include<conio.h>

void main()
{
     FILE *pt;
     int i;
     char ch;
     pt=fopen("test.txt","r");
     if(pt==NULL)

Structure size without sizeof operator

Q : Write a ‘C’ program to find size of structure without using sizeof operator.

Solution :


#include<stdio.h>
typedef struct stu
{
     int roll;
     char name[20];

Monday 21 August 2017

Write A Line to File

Q: Write a ‘C’ program to write a line of string at a text file.

Solution : 


#include<stdio.h>
void main()
{
     FILE *pt;
     char ar[100];
     int i;
     printf("Enter the Text>> ");
     gets(ar);
     pt=fopen("test.txt","w");
     if(pt==NULL)
          puts("Unable to open file");
     else
     {
          for(i=0;ar[i]!='\0';i++)
               putc(ar[i],pt);
     }
     printf("\nData created successfully");
     fclose(pt);
    
}

Saturday 19 August 2017

Sorting C Language Keyword Program

Q : Write a ‘C’ program to list of keywords which must be sorted in increasing order in the table.

Solution : 


#include<stdio.h>
int power(int,int);
void main()
{

     char keyword[][15]={"char","do","extern","if","return","static","union","while","case","default","enum","goto","register","