ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello I have a Database using C programming and text based screen using curses. When I run the program and select "add a customer". The startcontract and endcontract variable does not appear. Also, when I add a name, it does not display what I have written down. All that appears is some jargon which I don't know how to fix it.
#define MESSAGE_LINE 6 /* Misc. messages go here */ #define ERROR_LINE 20 /* The line to use for errors */ #define Q_LINE 25 /* Line for Questions */ #define PROMPT_LINE 18 /* Line for prompting on */
char *extended_menu[] = { "aadd new customer", "ffind customer", "ccount customers", "llist current customers", "rremove a current customer", "uupdate a customer", "qquit", 0, };
int main() { int choice;
initscr();
do { choice = getchoice("Options:", current_name[0] ? extended_menu : main_menu);
switch (choice) { case 'q': break;
case 'a': add_customer(); break;
case 'c': count_customer(); break;
case 'f': find_customer(); break;
case 'l': list_customer(); break;
case 'r': remove_customer(); break;
case 'u': update_customer(); break; } } while (choice != 'q');
endwin(); exit(EXIT_SUCCESS);
}
int getchoice(char *greet, char *choices[]) { static int selected_row = 0; int max_row = 0; int start_screenrow = MESSAGE_LINE, start_screencol = 10; char **option; int selected; int key = 0;
option = choices; while (*option) { max_row++; option++; } if (selected_row >= max_row) selected_row = 0;
void list_customer() { FILE *address_fp; char entry[MAX_ENTRY]; int address_length; int lines_op = 0; WINDOW *address_pad_ptr; int address = 0; int key; int first_line = 0;
if (current_name[0] == '\0') { mvprintw(ERROR_LINE, 0, "You must select a name first. ", stdout); get_return(); return; } clear_all_screen(); address_length = strlen(current_address);
address_fp = fopen(address_file, "r"); if (!address_fp) return; while (fgets(entry, MAX_ENTRY, address_fp)) { if (strncmp(current_address, entry, address_length) == 0) address++; } fclose(address_fp); address_pad_ptr = newpad(address + 1 + BOXED_LINES, BOXED_ROWS + 1); if (!address_pad_ptr) return;
address_fp = fopen(address_file, "r"); if (!address_fp) return;
void update_customer() { FILE *address_fp; char address_name[MAX_STRING]; int len; int address = 1; int screen_line = 1; WINDOW *box_window_ptr; WINDOW *sub_window_ptr;
clear_all_screen(); mvprintw(PROMPT_LINE, 0, "Re-entering address for customer. "); if (!get_confirm()) return; move(PROMPT_LINE, 0); clrtoeol();
remove_address();
mvprintw(MESSAGE_LINE, 0, "Enter a blank line to finish");
address_fp = fopen(address_file, "a");
/* Just to show how, enter the information in a scrolling, boxed, window. The trick is to set-up a sub-window, draw a box around the edge, then add a new, scrolling, sub-window just inside the boxed sub-window. */ box_window_ptr = subwin(stdscr, BOXED_LINES + 2, BOXED_ROWS + 2, BOX_LINE_POS - 1, BOX_ROW_POS - 1); if (!box_window_ptr) return; box(box_window_ptr, ACS_VLINE, ACS_HLINE);
I think you will get more help if you reduce the problem to something smaller that is still fully reproducible. While doing so, you may well discover your error all by yourself. If you have little or no prior programming experience, then this is where you start learning to debug your program. At the very least, it would be helpful to point out where in the source code the faulty output is expected to be coming from. In describing your problem, try to use terms that are more generic; no one but you understands the domain of the application, but many here probably understand the general methods you are trying to employ.
$ gcc -std=c99 -pedantic -Wall -Wextra shh226.c -lncurses -o shh226
shh226.c: In function ‘find_customer’:
shh226.c:335:9: warning: suggest parentheses around assignment used as truth value
shh226.c:339:9: warning: suggest parentheses around assignment used as truth value
shh226.c:343:13: warning: suggest parentheses around assignment used as truth value
$ ./shh226
Account system
Enter New Customer Details:
Enter Name: tom
Enter Address: 3 red lane
Enter Email: tom@mail.com
Enter Payment: 230
Enter Start Contract: sc
Enter Contract Expiry Date: ced
About to add this new entry:
tom,3 red lane,tom@mail.com,230,sc,ced
Are you sure?
Yes, it seems to work for me, too. The nature of the garbage characters printed makes me think the problem is related to the actual screen handling. I wonder if the OP is testing with some obscure terminal type not supported by curses. I tested with RHEL4, KDE Konsole and with xterm.
--- rod.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.