home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / mac / programm / 21991 < prev    next >
Encoding:
Text File  |  1993-01-23  |  2.2 KB  |  88 lines

  1. Path: sparky!uunet!olivea!pagesat!netsys!agate!stanford.edu!rock!concert!duke!news.duke.edu!acpub.duke.edu!gk1
  2. From: gk1@acpub.duke.edu (Gavin  Kistner)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Beginner Think C question
  5. Summary: Crashes normally, not in debug
  6. Message-ID: <8990@news.duke.edu>
  7. Date: 23 Jan 93 00:14:15 GMT
  8. Sender: news@news.duke.edu
  9. Followup-To: gk1@acpub.duke.edu
  10. Organization: Duke University; Durham, N.C.
  11. Lines: 74
  12. Nntp-Posting-Host: raphael.acpub.duke.edu
  13.  
  14. I'm trying to write my very first program on a Mac (except hello world)
  15. using Think C 5.0.2  & Think Reference.
  16. I'm fuddling along, and things are working alright if I'm stepping through
  17. in the debugger, but if I try to run the program without it, it crashes
  18. immediately.  Not even CMD-OPT-ESC saves.  I'd think I'm trashing system
  19. mem, but it does work fine with the debugger.
  20.  
  21. Code follows.  Please understand that this is my very first program
  22. attempting to use any procedures not my own.  The code is messy.  Bear with
  23. me.
  24.  
  25. #include <Resources.h>
  26. #include <Types.h>
  27. #include <StandardFile.h>
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30.  
  31. short GetFiles(void);
  32.  
  33. #define NIL 0
  34. short fileRefs_g[255];
  35.  
  36. /*********************************************/
  37.  
  38. int
  39. main()
  40. {
  41.        short error;
  42.        
  43.        error = GetFiles();
  44.        
  45.        return 0;        
  46. } /*main*/
  47.  
  48. /*********************************************/
  49.  
  50. short
  51. GetFiles()
  52. {
  53.        short loopCounter=0;
  54.        SFReply openReply;
  55.        Point boxPoint;
  56.        SFTypeList fileKind;
  57.        
  58.        boxPoint.v = 20;
  59.        boxPoint.h = 20;
  60.        fileKind[0]='sfil';
  61.        openReply.good = 1;
  62.        
  63.        while (openReply.good && (loopCounter < 256))
  64.                 {
  65.                 SFGetFile(boxPoint,NIL,NIL,1,fileKind,NIL,&openReply);
  66.                 if (openReply.good)
  67.                         fileRefs_g[loopCounter++] =
  68. OpenResFile(openReply.fName);
  69.                 if (openReply.good && (fileRefs_g[loopCounter-1] == -1))
  70.                         {
  71.                         printf("An error occured opening the selected
  72. resource file.\n");
  73.                         printf("Sorry.\nExiting program...\n");
  74.                         exit(1);
  75.                         } /*if*/
  76.                 } /*while*/
  77.  
  78.        if (loopCounter < 3) return 1;
  79.        else return 0;
  80. } /*GetFile*/
  81.  
  82. Anyone feeling like taking the time to look over this, and flame me if they
  83. find out what's wrong, please do so.
  84.  
  85. Thanks, 
  86.  
  87.                    Gavin
  88.