Qingjun, thanks for your prompt reply. Unfortunately it still doesn't work. Your script does read the string but scanf stops at the first white space. I've discovered something interesting about my problem with reading in strings. What should and does work from the command line is root [0] char comment[200] root [1] printf("What is your comment ?") root [2] gets(comment) This is a comment (char* 0x540720)"This is a comment\n" root [3] printf("The comment was %s : \n",comment) The comment was : This is a comment (const int)36 root [4] This does work when I type in each command in turn at the root prompt. However, when the the above code is in a root macro, the line, gets(comment) is completely skipped. ie, the following code produces the following output void scanner_new(){ char comment[200]; printf("Any comments ? : "); gets(comment); printf("The comment was : %s \n",comment); } root [0] Any comments ? : root [1] The comment was : So, it appears that my problem may be with cint interpreting the function, gets. I should point out that I'm using root on a Windows NT PC. The root version is 2.24/05. Any suggestions ? 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 ====================================================== On Thu, 1 Mar 2001, Qingjun Liu wrote: > > 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