#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
typedef struct {
int cmdIdx;
char *funcName;
} test_case_info;
test_case_info test_case[] =
{
{0, "test_case1"},
{1, "test_case2"},
{2, "test_case3"},
{3, "test_case4"},
{4, "test_case5"},
{-1, NULL}
};
void print_help(void)
{
int i = 0;
printf("Supported test cases:\n");
while (test_case[i].cmdIdx != -1) {
printf("%d:\t%s\n", test_case[i].cmdIdx, test_case[i].funcName);
i++;
}
}
int main(int argc, char *argv[])
{
int cmd_index = 0;
int ret = 0;
print_help();
while (1) {
printf("please input cmd index(exit_index:-1): ");
fflush(stdin);
scanf("%d", &cmd_index);
printf("cmd_index:%d\n", cmd_index);
if (cmd_index == -1)
break;
switch (cmd_index) {
case 0: {
char temp[32] = {0};
int flag = 0;
int string_length = sizeof(temp);
printf("please input file name[%d]: \n", string_length);
fflush(stdin);
scanf("%s", temp);
printf("please input file flag(1:O_RDWR, 2:O_RDONLY ): \n");
fflush(stdin);
scanf("%d", &flag);
switch (flag) {
case 1:
flag = O_RDWR;
break;
case 2:
flag = O_RDONLY;
break;
default:
break;
}
string_length = strlen(temp);
printf("content:%s, length:%d\n", temp, string_length);
break;
}
default: {
print_help();
break;
}
}
}
return 0;
}
linux 交互简单实例
最新推荐文章于 2023-07-14 13:30:10 发布