Tuesday, 4 November 2014

Program to copy the contents of one file into another using fgetc and fputc function

#include<stdio.h>
#include<process.h>

void main() {
   FILE *fp1, *fp2;
   char a;
   clrscr();

   fp1 = fopen("test.txt", "r");
   if (fp1 == NULL) {
      puts("cannot open this file");
      exit(1);
   }

   fp2 = fopen("test1.txt", "w");
   if (fp2 == NULL) {
      puts("Not able to open this file");
      fclose(fp1);
      exit(1);
   }

   do {
      a = fgetc(fp1);
      fputc(a, fp2);
   } while (a != EOF);

   fcloseall();
   getch();
}

Output :
1
Content will be written successfully to file

Program to Print All ASCII Values in C Programming Program :



CODE :


   
#include<stdio.h>

void main() {
   int i = 0;
   char ch;

   for (i = 0; i < 256; i++) {
      printf("%c ", ch);
      ch = ch + 1;
   }
}



OUTPUT :

e f g h i j k l m n o p q r s t u v w x y z { | } ~ ⌂ Ç ü é â ä à å
ç ê ë è ï î ì Ä

C Program for Beginners : Area of Rectangle





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

int main() {
   int length, breadth, area;

   printf("\nEnter the Length of Rectangle : ");
   scanf("%d", &length);

   printf("\nEnter the Breadth of Rectangle : ");
   scanf("%d", &breadth);

   area = length * breadth;
   printf("\nArea of Rectangle : %d", area);

   return (0);
}