Saturday, May 9, 2020

c prog mv cmd

c program to implement mv command in linux

#include<sys/types.h>
#include<sys/stat.h>
#include<stdio.h>
#include<fcntl.h>
main( int argc,char *argv[] )
{
int i,fd1,fd2;
char *file1,*file2,buf[2];
file1=argv[1];
file2=argv[2];
printf("file1=%s file2=%s",file1,file2);
fd1=open(file1,O_RDONLY,0777);
fd2=creat(file2,0777);
while(i=read(fd1,buf,1)>0)
write(fd2,buf,1);
remove(file1);
close(fd1);
close(fd2);
}

Output:

student@ubuntu:~$gcc –o mvp.out mvp.c
student@ubuntu:~$cat > ff
hello
hai
student@ubuntu:~$./mvp.out ff ff1
student@ubuntu:~$cat  ff
cat:ff:No such file or directory
student@ubuntu:~$cat ff1
hello
hai

c prog on line


C program to display different types of lines


#include <graphics.h>
#include <conio.h>

int main()
{
//initializing graphic driver and
//graphic mode variable
int graphicdriver=DETECT,graphicmode;

//calling initgraph
initgraph(&graphicdriver,&graphicmode,"c:\\turboc3\\bgi");

//Printing message for user
outtextxy(20, 20 + 20, "Program to set different styles of lines in C graphics");

//initilizing the variables
int c , x = 120, y = 80;

//for loop to set different styles of line
for ( c = 4 ; c >= 0 ; c-- )
{
setlinestyle(c, 0, 3);
line(x, y, x+150, y);
y = y + 20;
}

getch();

return 0;
}

2D array

Two Dimensional Array in C


Two Dimensional Array in C
The two-dimensional array can be defined as an array of arrays. The 2D array is organized as matrices which can be represented as the collection of rows and columns. However, 2D arrays are created to implement a relational database lookalike data structure. It provides ease of holding the bulk of data at once which can be passed to any number of functions wherever required.

Declaration of two dimensional Array in C
The syntax to declare the 2D array is given below.

data_type array_name[rows][columns];  
Consider the following example.


int twodimen[4][3];  
Here, 4 is the number of rows, and 3 is the number of columns.

Initialization of 2D Array in C
In the 1D array, we don't need to specify the size of the array if the declaration and initialization are being done simultaneously. However, this will not work with 2D arrays. We will have to define at least the second dimension of the array. The two-dimensional array can be declared and defined in the following way.

int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};  
Two-dimensional array example in C

#include<stdio.h>  
int main(){      
int i=0,j=0;    
int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};     
//traversing 2D array    
for(i=0;i<4;i++){    
 for(j=0;j<3;j++){    
   printf("arr[%d] [%d] = %d \n",i,j,arr[i][j]);    
 }//end of j    
}//end of i    
return 0;  
}    


Friday, May 8, 2020

Storage devices

What is a storage device

A storage device refers to a computing hardware used to store information permanently or temporarily. The device can be external or internal to a computer, server, and other computing systems. Storage devices are also known as storage medias or storage medium. There are two types of storage device: secondary storage device and primary storage device.

Secondary storage device

A secondary storage device has a larger storage capacity and can store data permanently. The device can be both external and internal to a computer and includes; compact disk, USB drive, hard disk, etc.

Primary storage device

A primary storage device is quite smaller in size and it’s designed to capture or hold data for a temporary period. Most primary storage devices are found inside the computer, and they have the fastest access to data. Examples of Primary devices include Cache memory and RAM.

Examples of Storage Device

  • Magnetic Storage Device – one of the most popular types of storage used.
    • Floppy diskette – A normal 3 ½ inch disk can store 1.44 MB of data.
    • Hard drive – An internal hard drive is the main storage device in a computer. An external hard drive is also known as removable hard drive.  It is used to store portable data and backups.
    • Magnetic strip – Magnetic tape drive stores video and audio using magnetic tape, like tape and video tape recorders.
    • Super disk – A disk drive and diskette that can hold 120 MB and 240 MB of data.

  • Optical Storage Device – uses lasers and lights as its mode of saving and retrieving data.
    • Blu-ray disc – A digital optical storage device which was intended to replace the DVD format.
    • CD-ROM disc – An optical storage device that is read-only or cannot be modified nor deleted.
    • CD-R and CD-RW disc – CD-R is a recordable disc that can be written to once, while CD-RW is a rewritable disc that can be written to multiple times.
    • DVD-R, DVD+R, DVD-RW and DVD+RW disc – DVD-R and DVD+R are recordable discs that can be written to once, while DVD-RW and DVD+RW are rewritable discs that can be written to multiple times. The difference between the + and – is in the formatting and compatibility.

  • Flash Memory Device – is now replacing magnetic storage device as it is economical, more functional and dependable.
    • Memory card – An electronic flash memory device used to store digital information and commonly used in mobile electronic devices.
    • Memory stick – A memory card that is removable.
    • USB flash drive, jump drive or thumb drive – A small, portable storage device connected through the USB port.

  • Online and Cloud – is now becoming widespread as people access data from different devices.
    • Cloud storage – Data is managed remotely and made available over a network. Basic features are free to use but upgraded version is paid monthly as a per consumption rate.
    • Network media – Audio, Video, Images or Text that are used on a computer network. A community of people create and use the content shared over the internet.

  • Paper Storage – method used by early computers for saving information.
    • OMR – stands for Optical Mark Recognition – A process of capturing marked data of human from forms like surveys and tests. It is used to read questionnaires with multiple choices that are shaded.
    • Punch card – A piece of hard paper used to contain digital information coming from the perforated holes.  The presence or absence of holes in predetermined positions define the data.

C prog print nos

C program to print all the numbers between A and B


#include<stdio.h>
void main()
{
    int num,a,b;
    clrscr();
    printf ("Enter range (a,b) : ") ;
    scanf ("%d %d", &a, &b);
    for (num = a; num <= b; num++)
             {
                printf("%d ", num);
             }
    getch();
}