Slimelite BBS

Thanks...

Back to EMULATE

From Cliff Rhodes · 1996-04-01 15:15 · #73524 in EMULATE

--> Greg Aluise wrote to All  <--

GA>        I am trying to get an integer out of the following code:

GA>   int var1;
GA>   int var2;
GA>   char buffer[80];
GA>   char *string
GA> 
GA>   cout <<"Enter a number:";
GA>   buffer[0]=3;
GA>   string = cgets(buffer);
GA>   v1 = int(string);

You cannot convert a string to an int value with int(), this is an error. 
You must use a specific conversion routine like atoi().

v1 = atoi(string);

of course

cin >> v1;

would be a lot easier!
___
 * CMPQwk 1.4 #1692 * "A sad tale's best for winter." - William Shakespeare

--- Maximus/2 3.01
 * Origin: COMM Port OS/2 (713) 980-9671 (1:106/2000)