Click here to Skip to main content
15,921,542 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Exporting from a DLL Pin
Zac Howland7-Jul-06 6:18
Zac Howland7-Jul-06 6:18 
QuestionUser Input Pin
Harold_Wishes7-Jul-06 5:26
Harold_Wishes7-Jul-06 5:26 
AnswerRe: User Input Pin
Zac Howland7-Jul-06 5:31
Zac Howland7-Jul-06 5:31 
GeneralRe: User Input Pin
Harold_Wishes7-Jul-06 5:51
Harold_Wishes7-Jul-06 5:51 
GeneralRe: User Input Pin
Zac Howland7-Jul-06 6:04
Zac Howland7-Jul-06 6:04 
GeneralRe: User Input Pin
Harold_Wishes7-Jul-06 7:06
Harold_Wishes7-Jul-06 7:06 
GeneralRe: User Input Pin
Zac Howland7-Jul-06 7:33
Zac Howland7-Jul-06 7:33 
GeneralRe: User Input Pin
Harold_Wishes7-Jul-06 10:08
Harold_Wishes7-Jul-06 10:08 
Hello again,

I did run my program and caught a runtime error with the cin.getline(buffer, 500, '\n'); I have a condensed working version below of the program compiled using Visual C++. One of my cin input streams is not being read in. It is skipped automatically and just goes to the next input prompt. I have not been able to figure out why this is happening.

I have 2 functions in main(). The problem seems to be when I move from function 1 to function 2 (the runtime error occurs in function 2). Oddly enough, the problem disappears when I comment out function 1 and only execute function 2. If you have a complier and execute the program (at least with Visual C++), you may see what I mean.

Regards Blush | :O


#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cctype>
#include <iomanip>
#include "unsortedlist.h"
#include "sortedlist.h"


using std::string;
using namespace std;


struct node                                                         //
{
     string Length;                   //
     string Sequence;                                               //  
     string N_Terminal;                                             // 
     string C_Terminal;
     node *nxt;// Pointer to next node
};


node *start_ptr = NULL;
node *current;		 // Used to move along the list


void add_Part_one (string& data1, int& data2)
{
      string selection = "A";
	cout << "Please Select the sequence type: " << endl;
	cout << endl;
	cout << "A) Complete  B) Partial  C) UNKNOWN" << endl;
   

      cin >> selection;

      while (selection != "A" && selection != "a" && selection != "B" && selection != "b" 
	 && selection != "C" && selection != "c")
	{
	       cout << "Invalid Entry. Please Try Again: " << endl;  
		 cin >> selection;
	}

     
	if ( selection == "A" || selection == "a" )
      {
	     data1 = "Complete";
	}
	else
	if ( selection == "B" || selection == "b" )
      {
	     data1 = "Partial";
      }
	else
	if ( selection == "C" || selection == "c" )
      {
		 data1 = "UNKNOWN";
      }
	

	cout << "Please enter the number of subunits: ";
      cin >> data2;
}

void add_node_at_end()
{        
    node *temp, *temp2;  // Temporary pointers
	temp = new node; // Reserve space for new node and fill it with data
	 
	

    char buffer[501] = {0};

	cout << "Please enter the length of the protein sequence: ";
	cin.getline(buffer, 500, '\n');
	temp->Length = buffer;
    memset(buffer, 0, 501);


	cout << "Please enter the protein sequence : ";
    cin.getline(buffer, 500, '\n');
    temp->Sequence = buffer;
    memset(buffer, 0, 501);


	cout << "Enter brief status on the presence of a modified N_Terminal: ";
    cin.getline(buffer, 500, '\n');
    temp->N_Terminal = buffer;
    memset(buffer, 0, 501);

	cout << "Enter brief status on the presence of a modified C_Terminal: ";
    cin.getline(buffer, 500, '\n');
    temp->C_Terminal = buffer;
    memset(buffer, 0, 501);


    
	temp->nxt = NULL;

      // Set up link to this node
	if (start_ptr == NULL)
	{ start_ptr = temp;
		 current = start_ptr;
	}
      else
	{ temp2 = start_ptr;
	  // We know this is not NULL - list not empty!
	  while (temp2->nxt != NULL)
	  {  temp2 = temp2->nxt;
				  // Move to next link in chain
	  }
	     temp2->nxt = temp;
	}
      	 cout << endl;
}

int main()
{
   int number_of_subunits = 1;
   string SEQUENCE_TYPE;
   
   add_Part_one(SEQUENCE_TYPE, number_of_subunits);
   for (int counter = 0; counter < number_of_subunits; counter++)
   {  
	 add_node_at_end();

   }


return 0;
}


HRW
GeneralRe: User Input [modified] Pin
Zac Howland7-Jul-06 10:35
Zac Howland7-Jul-06 10:35 
GeneralRe: User Input [modified] Pin
Harold_Wishes8-Jul-06 17:36
Harold_Wishes8-Jul-06 17:36 
GeneralRe: User Input Pin
Zac Howland9-Jul-06 14:28
Zac Howland9-Jul-06 14:28 
QuestionSimple MAPI Outlook outbox problem Pin
chilituna7-Jul-06 4:45
chilituna7-Jul-06 4:45 
Questionostream operator link error Pin
mosu'7-Jul-06 4:33
mosu'7-Jul-06 4:33 
AnswerRe: ostream operator link error [modified] Pin
Viorel.7-Jul-06 4:45
Viorel.7-Jul-06 4:45 
AnswerRe: ostream operator link error Pin
Zac Howland7-Jul-06 5:11
Zac Howland7-Jul-06 5:11 
QuestionRun an application inside another one Pin
xtof737-Jul-06 4:03
xtof737-Jul-06 4:03 
AnswerRe: Run an application inside another one Pin
Sarath C7-Jul-06 4:25
Sarath C7-Jul-06 4:25 
GeneralRe: Run an application inside another one Pin
Zac Howland7-Jul-06 4:30
Zac Howland7-Jul-06 4:30 
GeneralRe: Run an application inside another one Pin
Sarath C7-Jul-06 4:39
Sarath C7-Jul-06 4:39 
AnswerRe: Run an application inside another one Pin
Jun Du7-Jul-06 4:40
Jun Du7-Jul-06 4:40 
QuestionCListCtrl and Graphic Pin
ensger7-Jul-06 3:44
ensger7-Jul-06 3:44 
AnswerRe: CListCtrl and Graphic Pin
Zac Howland7-Jul-06 5:25
Zac Howland7-Jul-06 5:25 
GeneralRe: CListCtrl and Graphic Pin
ensger7-Jul-06 9:10
ensger7-Jul-06 9:10 
QuestionCreating a Bitmap from a Framegrabber Image Pin
im797-Jul-06 3:41
im797-Jul-06 3:41 
AnswerRe: Creating a Bitmap from a Framegrabber Image Pin
Justin Tay7-Jul-06 6:27
Justin Tay7-Jul-06 6:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.