C Program to Sort the numbers and store them in file using user define function

C Program to Sort the numbers and store them in file using user define function

C Program to Sort the numbers and store them in file using user define function

#include

int bubble(int*,int);
void filewrite();
void avgmarks();
void fileprint();
void filesort();
void rollin();

/*********************** SORTING FUNCTION ***************************/
int bubble(int x[],int n)
{
int hold,j,pass,i,switched = 1;
for(pass = 0; pass < n-1 && switched == 1;pass++) { switched=0; for (j=0;jx[j+1])
{
switched=1;
hold = x[j];
x[j] = x[j+1];
x[j+1]=hold;
}
}
return(0);
}
/*********************** FILE WRITING FUNCTION ******************************/

void filewrite()
{
int roll,ch,mark;
char nam[50];
FILE *fp;
clrscr();
fp = fopen("student.txt","a");
printf("ENTER ROLL NUMBER, NAME , MARKS \n");
ch =1;
while(ch)
{
scanf("%d%s%d",&roll,&nam,&mark);
fprintf(fp,"%d %s %d\n",roll,nam,mark);
printf("\n\n press 1 to continue,0 to stop");
scanf("%d",&ch);
}
fclose(fp) ;
}
/******************** OUTPUTING DATA ON SCREEN***************/
void fileprint()
{
int marks[100],rollno[100],x[100],i;
char name[100][50];
FILE *fp;

clrscr();
fp = fopen("student.txt","r");
i=0;
printf("ROLLNO NAME MARK\n");
while(!feof(fp))
{
fscanf(fp,"%d %s %d\n",&rollno[i],&name[i],&marks[i]);
printf(" %d %s %d\n",rollno[i],name[i],marks[i]);
i=i+1;
}
fclose(fp);
printf("\n\n\nPRESS ANY KEY");
getch();

}
/******************* SORTING FILE ************************/
void filesort()
{ int marks[100],rollno[100],x[100],n,i,j;
char name[100][50];
FILE *fp,*fm;

fp = fopen("student.txt","r");
fm = fopen("marks.txt","w");
i=0;
while(! feof(fp))
{

fscanf(fp,"%d %s %d\n",&rollno[i],&name[i],&marks[i]);
x[i]= marks[i];
i=i+1;
}

n=i;

bubble(x,n);

for(i=0;i

Related Links :

No comments:

Post a Comment


If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE


More Useful Topics...

 

History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming
language.

My 1st Program...


#include
#include
void main ()
{
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();
}

Next Step...


#include
#include

void main ()
{
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();

}

Hits!!!