Hi, I have tried the following code, which worked fine. However, when replaced scanf() with gets(), I ran into the same problem as you reported. void doit(){ gROOT->Reset(); char *as; as = new char [200]; printf("enter your comments\n"); scanf("%s",as); printf("Here is your comment: %s\n",as); int h; printf("New: enter hybrid serial number:"); scanf("%d", &h); printf("You entered hybrid serial number, which is %d\n",h); delete [] as; } Qingjun ******************************************************************* *Dr. Qingjun Liu * *CENPA Phone: (206) 616-8141 (O) * *University of Washington (206) 985-1666 (H) * *P.O. Box 354290 Fax : (206) 685-4634 * *Seattle, WA 98195 Email: qjliu@gibbs.npl.washington.edu * ******************************************************************* On Thu, 1 Mar 2001, Craig Everton wrote: > > > 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