I wrote a little program to maintain a household inventory and it exits before it get the input from the keyboard.
here is the code:
Code:
#include <stdio.h>
#include <string.h>
void select_mode();
void add_item(FILE *out);
/*void delete_item(FILE *out);
void search_item(FILE *out);
void edit_item(FILE *out);*/
typedef struct
{
char make[30],
model[30],
serialnum[30],
item_desc[4000];
}INV_ITEM;
INV_ITEM item;
int main()
{
select_mode();
}
void select_mode()
{
char mode;
FILE *out;
out=fopen("inv_file","a");
printf(" add an item (1)\n");
printf(" delete an item (2)\n");
printf(" search for an item (3)\n");
printf(" edit an item (4)\n");
printf(" What would you like to do: ");
mode=getchar();
switch (mode)
{
case '1': add_item(out);
break;
case '2': printf("delete_item(out);");
break;
case '3': printf("search_item(out);");
break;
case '4': printf("edit_item(out);");
break;
default : printf("You must choose one of the select menu items");
select_mode();
break;
}
fclose(out);
}
void add_item(FILE *out)
{
char *ptr;
fprintf(stdout,"Enter the name of the maker : ");
fgets(item.make, sizeof(item.make), stdin);
fprintf(stdout,"%s|",item.make);
}
it prints out the "Enter the name of the maker " and then goes straight to a unix prompt.