CompuServe Messages

switch()

    18-Dec-91 23:21:14
Sb: #17921-switch()
Fm: John Toebes/SYSOP 70007,3467
To: Rob Salmon 71420,471
My suggestion would be to do the following: 1) Create a table which has a series of strings and constants: struct TABLE { int value; char *string } look[] = { { 1, "option1"}, {2, "nopage"}, {3, "format"}, {4, "resize"} }; 2) Write a routine that takes the string to compare and the based of the table and searches for that string in the table. If found, it returns the value associated with the string. Otherwise it returns an error. 3) In your main code, just switch on the value returned from this function. The nice thing about this function is that you can teach it about abbreviations without having to change any of your code. John A. Toebes, VIII – via Whap!