c++ - Switch Statement Not Allowing First User Input -


this function checks two-dimensional char array , goes through each word in array, using size, searching > take switch statement searching cases.

i having problem in switch statement, user input first time switch statement goes through default case.

void parseword(char story[][256], int size) {    (int = 0; < size; i++)    {       char prompt[256][32];       if (story[i][0] == '<')       {          switch (story[i][1])          {             case '#':                story[i][0] = '\n';                story[i][1] = 0;                break;             case '{':                story[i][0] = ' ';                story[i][1] = '\"';                story[i][2] = 0;                break;             case '}':                story[i][0] = '\"';                story[i][1] = ' ';                story[i][2] = 0;                break;             case '[':                story[i][0] = ' ';                story[i][1] = '\'';                story[i][2] = 0;                break;             case ']':                story[i][0] = '\'';                story[i][1] = ' ';                story[i][2] = 0;                break;             default:                int p = 1;                 prompt[i][0] = (char)(toupper(story[i][1]));                (int j = 2; story[i][j] != '>'; j++)                {                   if (story[i][j] == '_')                      prompt[i][p] = ' ';                   else                      prompt[i][p] = story[i][j];                   p++;                }                 cout << '\t' << prompt[i] << ": ";                 cin.getline(prompt[i], 32);                 int z = 0;                (int t=0; prompt[i][t] != '\0'; t++)                {                   story[i][t] = prompt[i][t];                   z++;                }                 story[i][z] = 0;            }       }    }     return; } 

cin.getline(prompt[i], 32); having problem first time ran.

this output when run function, user input in *'s:

 web site name:  verb: *run*  plural noun: *dogs*  plural noun: *cats*  proper noun: *jimmy*  adjective: *smart*  noun: *table*  noun: *desk*  boolean operator: *xor*  noun: *shoe*  favorite website: *google.com*  website: *yahoo.com*  adjective: *cold*  emoticon: *:p* 

as can see, cin.getline(prompt[i], 32) skipped when code ran , right away goes next prompt , asks user input. not making entered in verb equal web site name should be, not allowing entered web site name , making empty. verb still equal to, in case "run".

why switch statement seemingly skipping cin.getline(prompt[i], 32) statement first time around? times default case ran after first seem working expected , can't see or understand why user input not allowed first time default case ran in switch.

thanks help!

i found in other functions in program received input cin. looking @ why getline skips first line? saw cin , cin.getline() don't work together. after trying cin.ignore() statements (which fixed problem created many others) decided exclusively input using cin.getline(). inputs work now.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -