Tuesday, 16 September 2014

C++ Program to create RAMDRIVE or RAMDISk and run Calculator Program in it.

1. Create Input File in /tmp/ramdisk for input
          name it as input.txt

2. Write a Program for calculator in C

code is as follow

#include<stdio.h>
#include<stdlib.h>
int main()
{
 int a,b,res;
 FILE *fp;
 fp=fopen("/tmp/ramdisk/input.txt","r");
 fscanf(fp,"%d",&a);
 fscanf(fp,"%d",&b);
 fclose(fp);
  fp=fopen("/tmp/ramdisk/output.txt","w");
 fprintf(fp,"\n Addition is :%d ",(a+b));
return 0;
}


save it as calci.c and compile using command
          gcc calci.c -o  calculator


3. Write program for RAMDISK in C language
     
    #include<stdio.h>
#include<stdlib.h>
int main()
{
  printf("\n RAMDISK creation for 512M size");
  system("rmdir /tmp/ramdisk");
  system("mkdir /tmp/ramdisk");
  system("chmod 777 /tmp/ramdisk");
  system("mount -t tmpfs -o size=512M tmpfs /tmp/ramdisk/");
  printf("\n RAMDISK created");
  system("df -h|grep ram");
  system("cp input.txt /tmp/ramdisk");
  system("cp calculator /tmp/ramdisk");
  return 0;
}

save it as ramdisk.c and compile as

gcc ramdisk.c -o ramdisk

execute output of above command as
        ramdisk <Enter>

4. Calculator code can be executed using command
        /tmp/ramdisk/calculator

5. Output is saved in output.txt file. Check it from /tmp/ramdisk/output.txt





1 comment:

  1. Calculator program in C

    In C language we can design a program to add, subtract, multiply, divide any number, these all operation you can perform by using switch case.

    ReplyDelete