home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16138 < prev    next >
Encoding:
Text File  |  1992-11-11  |  2.1 KB  |  81 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!europa.asd.contel.com!emory!swrinde!cs.utexas.edu!sun-barr!sh.wide!wnoc-kyo!kuis!kudpc!nucc!f43703a
  3. From: f43703a@nucc.cc.nagoya-u.ac.jp (SUPRATIC GUPTA)
  4. Subject: HGelp needed - C++
  5. Message-ID: <1992Nov12.040531.5051@nucc.cc.nagoya-u.ac.jp>
  6. Organization: Nagoya University Computation Center, Nagoya, Japan.
  7. Date: Thu, 12 Nov 1992 04:05:31 GMT
  8. Lines: 71
  9.  
  10.  
  11. Dear friends,
  12.     I am having a problem with C++, can you help me? Please answer
  13. to me directly.
  14.  
  15. #include <stream.h>
  16. #include <stdio.h>
  17. #include<stdlib.h>
  18. #include <string.h>
  19.    
  20. main(){
  21.     char* objname[2];
  22.     for(int i = 0; i < 3; ++i){
  23.         objname[i] = "UNDEFINED";
  24.     }
  25.     char* ZZZ = "                                        ";
  26.         if(k == 0) ZZZ = "aaaaaaaaa";
  27.         if(k == 1) ZZZ = "bbbbbbbbb";
  28.         if(k == 2) ZZZ = "ccccccccc";
  29.         for(i = 0; i < 3; ++i){
  30.             cout <<"after  " << i << "  "<<  objname[i] << endl;
  31.         }
  32.      objname[k] = ZZZ;
  33.     }
  34. }
  35.  
  36. The out put is OK It looks like this;
  37.  
  38. 0  UNDEFINED              1  UNDEFINED              2  UNDEFINED
  39. 0  aaaaaaaaa              1  UNDEFINED              2  UNDEFINED
  40. 0  aaaaaaaaa              1  bbbbbbbbb              2  UNDEFINED
  41.  
  42. But if I use this program;
  43.  
  44. #include <stream.h>
  45. #include <stdio.h>
  46. #include<stdlib.h>
  47. #include <string.h>
  48.  
  49. main(){
  50.     char* objname[2];
  51.     for(int i = 0; i < 3; ++i){
  52.         objname[i] = "UNDEFINED";
  53.     }
  54.     char* ZZZ = "                                        ";
  55.     for(int k = 0; k < 3; ++k){
  56.         cout << "INPUT > " cin >> ZZZ;
  57.         for(i = 0; i < 3; ++i){
  58.             cout << i << "  "<<  objname[i] << "              ";
  59.         }
  60.         cout << " " << endl;
  61.      objname[k] = ZZZ;
  62.     }
  63. }
  64.  
  65. The answer looks like this:
  66.  
  67. INPUT > aaaaaaaaa
  68. 0  UNDEFINED              1  UNDEFINED              2  UNDEFINED
  69. INPUT > bbbbbbbbb
  70. 0  bbbbbbbbb              1  UNDEFINED              2  UNDEFINED
  71. INPUT > ccccccccc
  72. 0  ccccccccc              1  ccccccccc              2  UNDEFINED
  73.  
  74. The answers are different, when the only difference is that in
  75. second case I am using "cin" for input. Can any one explain?
  76.  
  77. with regards
  78. SUPRATIC GUPTA
  79.  
  80.  
  81.