抱歉,又是我
*/
//#define debug
struct dimension
{
int num_row
int num_col
}
void table_set_entry (const int t[] ,const struct dimension *dim ,const int row ,const int col ,const int v)
{
if (t == 0 || dim == 0 || row <0 || col <0 || row >= dim->num_row || col >= dim->num_col)
return
t[col * dim->num_row + row] = v
return
}
int table_get_entry (const int t[] ,const struct dimension *dim ,const int row ,const int col)
{
if (t == 0 || dim == 0 || row <0 || col <0 || row >= dim->num_row || col >= dim->num_col)
return 0
return t[col * dim->num_row + row]
}
void table_clear (const int t[] ,struct dimension *dim)
{
if (t == 0 || dim == 0)
return
const int* pb = t
const int* pe = t + dim->num_row * dim->num_col
int* p
for (p = pb p <pe p++)
*p = 0
return
}
void table_copy (const int a[] ,const int b[] ,struct dimension *dim)
{
if (a == 0 || b == 0 || dim == 0)
return
const int* pab = a
const int* pae = a + dim->num_row * dim->num_col
int* pa
const int* pbb = b
int* pb
for (pa = pab ,pb = pbb pa <pae pa++ ,pb++)
*pb = *pa
return
}
#ifdef debug
int main ()
{
void table_set_entry (const int t[] ,const struct dimension *dim ,const int row ,const int col ,const int v)
int table_get_entry (const int t[] ,const struct dimension *dim ,const int row ,const int col)
void table_clear (const int t[] ,struct dimension *dim)
void table_copy (const int a[] ,const int b[] ,struct dimension *dim)
int t[10][10]
int f[100]
const struct dimension dim = {10 ,10}
const int row = 4
const int col = 7
const int v = 250
table_set_entry (t ,&dim ,row ,col ,v)
printf ("isn't %d equal to %d ?\n" ,t[col][row] ,table_get_entry (t ,&dim ,row ,col))
table_copy (t ,f ,&dim)
table_clear (t ,&dim)
printf ("t : %d while f : %d\n" ,t[col][row] ,f[col * dim.num_row + row])
return 0
}
#endif
1、如果只是想返回已经写好的主菜单页面的话可以直接在当前函数中结束位置调用主菜单所在的函数,如果想输入某值返回的话
就加个输入提示
比如
在其他函数页面加上“输入0返回主菜单”就可以在任意时候
输入0来返回
当然实现的时候也是输入语句加判断语句
加调用主菜单所在函数,调用前先调用清屏函数。
2、例程:
#include
int menu()
{ int rt
char str[256]
printf("1 ****\n")
printf("2 ****\n")
printf("3 ****\n")
printf("4 ****\n")
printf("5 退出程序\n")
printf("请选择,输入选项前面的数字后回车: ")scanf("%s",str)
if ( str[0]>='1' &&str[0]<='5' ) rt=str[0]-'0'else rt=0
return rt
}
void f1() {}
void f2() {}
void f3() {}
void f4() {}
void main()
{ int s,loop=1
while ( loop )
{ s=menu()
switch ( s )
{ case 1: f1()break
case 2: f2()break
case 3: f3()break
case 4: f4()break
case 5: loop=0break
default: break
}
}
}