?? text3.c
字號:
#include <stdio.h>
#include "text3.h"
void fileRead ( int *a , int *n )
{
char sname[10];//源文件
FILE *fp;
printf("please input your source file name:\n");
scanf("%s",sname);
fp = fopen(sname,"r");
if(fp==NULL)
{
printf("file open error\n");
exit(0);
}//打開源文件
for ( *n = 0 ; !feof(fp) ; (*n)++)
fscanf( fp,"%d", &a[*n] );
fclose (fp);
}
void fileWrite ( int *a , int n )
{
FILE *fp;
int i;
char rname[10];//結果文件
printf("please input your result file name:\n");
scanf("%s",rname);
fp=fopen(rname,"w");
if(fp==NULL)
{
printf("file open error\n");
exit(0);
}//打開結果文件
for ( i=0 ; i < n ; i++)
fprintf( fp, "%3d", a[i] );
fclose (fp);
}
void sort ()
{
char c;
int a[80],n;
printf ("which kind do you want to use:\n");
printf ("bubbleSort:(b)\ninsertSort:(i)\nselectSort:(s)\nexit:(e)\n");
c = getchar();
c = getchar();
printf ("you have chosen %c\n",c);
switch ( c )
{
case 'b': fileRead( a , &n);
bubbleSort ( a , n );
fileWrite ( a , n );
break;
case 'i': fileRead( a , &n);insertSort ( a , 0 , n );fileWrite ( a , n );break;
case 's': fileRead( a , &n);selectSort ( a , n );fileWrite ( a , n );break;
case 'e': return;
default: printf ("wrong choice!!!\n ");return;
}
}
void oper()
{
char c;
int a[80],n,j,t,m;
printf ("which kind of operation do you want to use:\n");
printf ("delete:(d)\ninsert:(i)\nfind:(f)\nexit:(e)\n");
c = getchar();
c = getchar();
printf ("you have chosen %c\n",c);
switch ( c )
{
case 'd':{
fileRead( a , &n);
printf ( "input the index you want to delete\n");
scanf ("%d",&j);
Delete ( a , &n , j);
fileWrite ( a , n );
break;
}
case 'i': {
fileRead( a , &n);
printf ( "input the index you want to insert\n");
scanf("%d",&j);
printf ( "input the number you want to insert\n");
scanf("%d",&t);
insert (a, &n , j , t);
fileWrite ( a , n );
break;
}
case 'f':{
fileRead( a , &n);
printf ( "input the number you want to find\n");
scanf("%d",&t);
m = bidivideFind (a,0,n-1,t);
fileWrite ( a , n );
if ( m != n )
printf ( "the number %d is in the %d place\n ", t, m );
else
printf ( "there is no such number\n");
break;
}
case 'e': return;
default: printf ("wrong choice!!!\n ");return;
}
}
void main()
{
char c;
while (1)
{
printf ("what do you want to do ?\n");
printf ("sort a number group;(s)\noperations to a sorted number;(o)\nexit;(e)\n");
;
c = getchar();
printf ("you have chosen %c\n",c);
switch ( c )
{
case 's': sort ();break;
case 'o': oper ();break;
case 'e': getchar();exit (0);
default:printf ("wrong choice!!!\n ");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -