home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / msdos / programm / 8071 < prev    next >
Encoding:
Text File  |  1992-07-25  |  4.5 KB  |  143 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!caen!uwm.edu!csd4.csd.uwm.edu!rca
  3. From: rca@csd4.csd.uwm.edu (Robert C Allender)
  4. Subject: MY problem? ...or Borland's? (also on comp.lang.c)
  5. Message-ID: <1992Jul25.163852.19770@uwm.edu>
  6. Originator: rca@csd4.csd.uwm.edu
  7. Sender: news@uwm.edu (USENET News System)
  8. Organization: Computing Services Division, University of Wisconsin - Milwaukee
  9. Date: Sat, 25 Jul 1992 16:38:52 GMT
  10. Lines: 131
  11.  
  12. I'm VERY new to C, but I can usually hold my own by R(ing)TFM.  This is 
  13. different.  I've checked through Borland's FAX document catalog (I use 
  14. Borland's C++ 3.0, but I use the standard C mode), ALL the manuals, a few 
  15. 3rd party books on Borland C ... nothing.  Here's the problem:
  16. I initialize a char * in main() and pass it to a function that gets a string, 
  17. passing the address of the string back to main().  If I try to print the 
  18. string back at main(), it works.  I pass the char * to the next function, and
  19. I can print the string at the beginning of that function, but by the end of 
  20. it, the string is garbage.  If I then pass the value to main() and send it to
  21. yet aother function, the array is empty.  I can put checks in anywhere and
  22. find the strlen() to be correct at ANY of the points where it won't print, 
  23. but the values get corrupt and then dissappear.  What am I doing wrong?
  24.  
  25. Here's the boiled-down code...
  26.  
  27. #include <everything that's needed>
  28. #define LENGTH 10
  29.  
  30. main_bkgrd();
  31. main_title();
  32. main_entry();
  33. get_info();
  34. char * scrollbox(char,int,int);
  35. next(char *);
  36. prev(char *);
  37. make_box(int,int);
  38. char * get_dir(char,int,int);
  39. char get_drive();
  40. clear_half(char *);
  41. list_dir(char *);
  42.  
  43. main() {
  44.   char drive, *c;
  45.   char dummy;
  46.  
  47.   clrscr();
  48.   main_bkgrd();
  49.   main_title();
  50.   main_entry();
  51.   make_box(61,10);
  52.  
  53.   do {
  54.     do {
  55.       drive=get_drive();
  56.     } while (drive == NULL);
  57.     c = scrollbox(drive,61,10);  <---- This gets a directory, etc. 
  58.   } while(!c);
  59.   
  60.   clear_half(c);                 <-- can print the array here BEFORE the end
  61.                      of the function, else it's garbage.
  62.   list_dir(c);                   <-- by this point the array values are GONE.
  63.  
  64.   scanf("%c",&dummy);            <-- Just holds the screen so I can see 
  65.   return (0);                        where it messed up and what it's doing.
  66. }
  67.  
  68. list_dir(char *dir)  {           <-- "c" from main()
  69.   char seekdir[100];             <-- define new array so that "\"'s can be 
  70.                      replaced with reqired "\\"'s  in 
  71.                      _dos_findfirst().
  72.   struct find_t z;                                
  73.   int count,end;                 <-- generic counters
  74.   int counta, countb;
  75.  
  76.   textcolor(3);
  77.   for (count=1; count<strlen(dir); count++)    <-- try printing the OLD array
  78.     cprintf("%c",dir[count]);                       for kicks (doesn't work)
  79.   
  80.   textcolor(0);
  81.   textbackground(1);
  82.   for(counta=1, countb=1; countb<strlen(dir); counta++, countb++) {
  83.      seekdir[counta] = dir[countb];
  84.      if (dir[countb] == '\\') {          <-- all this just sets up the NEW
  85.     counta++;                            array for processing by 
  86.     seekdir[counta] = '\\';              _dos_findfirst().
  87.      }
  88.   }
  89.   end = _dos_findfirst(seekdir,_A_NORMAL,&z);
  90.   while (!end)  {
  91.      cprintf(" %s\n",z.name);
  92.      end = _dos_findnext(&z);
  93.   }
  94.   return(0);
  95. }
  96.  
  97.  
  98. clear_half(char *p) {
  99.   int row, counter, max;
  100.   textbackground(0);
  101.   textcolor(7);
  102.   max=strlen(p);
  103.  
  104.   textbackground(1);
  105.   textcolor(7);
  106.   gotoxy(4,12);
  107.   cprintf("Directory of: ");
  108.   for (counter=1; counter<max; counter++)     <-- Print the array.  It WORKS
  109.     cprintf("%c",p[counter]);                     at this point!
  110.  
  111.   textbackground(0);
  112.   for(row=14; row<24; row++)  {
  113.     gotoxy(5,row);
  114.     cprintf("                                 <-- Just blanks out a line 
  115.   }                                               (didn't all fit on the page)
  116.  
  117.   textbackground(1);
  118.   textcolor(7);
  119.   for(row=13; row<23; row++)  {
  120.     gotoxy(4,row);
  121.     cprintf("                                                                          ");
  122.   }
  123.   return(0);
  124. }
  125.  
  126. If anyone knows how to fix this, I'd really appreciate the help.  If you can
  127. E-Mail me (rca@csd4.csd.uwm.edu), I'll post a summary of all the reasonable
  128. solutions.
  129.  
  130. Thanks
  131.  
  132. --------------------------------------------------------------------------
  133. | Robert C. Allender    |  "Exactly!" said Deep Thought. "So once you do | 
  134. | rca@csd4.csd.uwm.edu  |  know what the question actually is, you'll    | 
  135. | rca@bfs.uwm.edu       |  know what the answer means."                  | 
  136. |                       |        -The Hitchhiker's Guide to the Galaxy   | 
  137. --------------------------------------------------------------------------
  138. -- 
  139.  
  140.  
  141.  
  142.  
  143.