Author Topic: Basic Union Programs in C  (Read 2358 times)

thiruvasagamani

  • Old Members
  • Hero Member
  • *
  • Posts: 6887
    • View Profile
Basic Union Programs in C
« on: August 14, 2008, 11:00:08 am »
Program in C for IS Command

Here is the Sample Code Try this


Code: [Select]
#include <stdio.h>

int main(argc, argv)
int argc;
char * argv[];

{

union dir
{
struct dat
{
int inode;
char file[14];

}a;

char ch[sizeof(struct dat)];

};


union dir m;


int fs,i,j;



if (argc!=2)
{
printf("usage is wrong");
return;
}


fs=open (argv[1], 0);

if (fs==-1)
{
printf("file opening error");
getch();
return;
}


i=read(fs, m.ch, sizeof(struct dat));

while(i>0)
{
printf("%d\t%s\n", m.a.inode, m.a.file);
i=read(fs, m.ch, sizeof(struct dat));
}


close(fs);

getch();


Program in C for IN Command

Here is the Sample Code Try this

Code: [Select]
#include <stdio.h>
#include <conio.h>
#include <io.h>
int main(argc, argv)
int argc;
char * argv[];

{

int i;


if (argc!=3)
{
printf("usage is wrong");
return;
}


i=link(argv[1],argv[2]);

if (i==0)
printf("file are linked");

getch();


Thiruvasakamani Karnan