[ROOT] Problem with reading character strings

From: Craig Everton (everton@liszt.ph.unimelb.edu.au)
Date: Thu Mar 01 2001 - 09:33:49 MET


I've just recently started using Root. I'm having a lot of problems with
what I thought would be very simple. One of my buttons calls the
function scanner_new() which puts a few prompts at the command line for
reading a serial number (integer) and a comment (string). See below;

void scanner_new(){
  int h;
  int i = 0;
  char comment[200], a, cmt[200];
  char a;

  printf("New: enter hybrid serial number:");
  scanf("%d", &h);

  printf("Enter any comments:");
  gets(comment);

  printf("The comment is : %s \n",comment);
  
  e->SetHybrid(h,comment);
  e->ReadLastInfo();
  e->ResetAll();
}

There is no problem with reading in the hybrid number but the line

gets(comment);

is not recognized. There is no error message, the script just skips to the
next line in the code. I thought that perhaps the stdio.h library may need
to be included explicitely but adding the line 

G__loadfile("stdio.h") doesn't help.


I've tried many fixes such as;

printf("Enter any comments:");
  a=getchar();
  while (a != "\n") {
  a=getchar();
  comment[i] = a;
  putchar(a);
  i++;
  }

AND

printf("enter any comments");

while(cmt != "\n"){
scanf("%s",cmt);
strcat(comment, " ");
strcat(comment, cmt);
}

But "\n" and "\r" is never found so the while loop never exits.

I've also tried

 
  cmt = new TString();
  printf("Enter any comments:");
  cmt->ReadString(comment);



But get the error

Can't call TString::ReadString(comment) in current scope


I'd appreciate it if anyone could tell me where I'm going wrong.

Thanks in advance


Craig

-======================================================
Craig Everton
Experimental Particle Physics (EPP)
School of Physics 
University of Melbourne,  Victoria
AUSTRALIA    3010
Phone : (work)   (613) 9344 5075		
        (home)   (613) 9387 6726
Fax :            (613) 9347 4783
Email : everton@liszt.ph.unimelb.edu.au
======================================================



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:38 MET