Solved

NULL pointer assignment mark 2

Posted on 2000-04-18
6
285 Views
Last Modified: 2010-04-15
Original question...

#define FONTSIZE 256*8
                     unsigned char _far *UserFont;
                     unsigned char _far *OurFont;
                     void LoadFont(void);
                     void NewFont(unsigned char _far *font);
                     void OldFont(void);

                     void LoadFont(void)
                     {
                     FILE *fontfile;
                     if((OurFont = (char *)malloc(FONTSIZE)) == NULL)
                     {
                     puts("Not enough memory");
                     exit(1);
                     }
                     if((fontfile = fopen("pudgey.fnt", "rb")) == NULL)
                     {
                     puts("Can't open file");
                     exit(1);
                     }
                     fread(OurFont, FONTSIZE, 1, fontfile);
                     fclose(fontfile);
                     }

                     void NewFont(unsigned char _far *font)
                     {
                     UserFont = (char _far *)0x0000010E;
                     FP_SEG(font) = 0x010E;
                     FP_OFF(font) = 0x010C;
                     }

                     void OldFont(void)
                     {
                     FP_SEG(UserFont) = 0x010E;
                     FP_OFF(UserFont) = 0x010C;
                     }
Thanks to all the guys who responded to my previous question.  I'm sorry, I couldn't give points to all.  Click on the 1st that looked good.  Didn't seem to be an option to give to others.  Have made enquiries, though.

The R6001 error message is:
      run-time error R6001 - null pointer assignment
It seems to mean, the contents of my NULL segment are changing during my program's execution.

Tried:
((OurFont = (unsigned char _far *)malloc(FONTSIZE)) == NULL)
No Change.  But for once QC25 didn't give me any grief.  Can work with this.

FP_SEG(UserFont) = 0x010E;
FP_OFF(UserFont) = 0x010C;
UserFont = NULL
 and
UserFont = MK_FP(0x10E, 0x10C);
Courtesy of Alex.  Want him to have 200 points too!
No Change.  And still QC25 didn't complain.  Another 1 to work with.

Okay Guys, I'm trying to write a stand-alone program called I-Ching.  It's a Chinese philosophy.  Pulled down a few interesting fonts from the net.  Seem really to suit it.  Different formats? yeah.  Wouldn't mind being able to use some of the .TTF files.  I use QuickC 25.  Old, but, as I said, I like it.  It shows you what to write for different platforms.  One of Microsoft's better efforts!
0
Comment
Question by:mogden
  • 3
  • 2
6 Comments
 

Author Comment

by:mogden
ID: 2729254
Thank you to those as answered.  This is agreat site.
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 2730104
modgen, i don't understand:
>>UserFont = MK_FP(0x10E, 0x10C);
works or not?
And how you use value of UserFont?
>>Courtesy of Alex.  
>>Want him to have 200 points too!
 If code works, i can reply to you Q.



0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 200 total points
ID: 2738798
Sounds like a memory corruption problem to me. I've seen MS 6.0 issue this at program termination when you do fclose() twice on the same FILE*:

fclose(fontfile);
fclose(fontfile);

When does the problem occur? Can you trace it to an individual statement? Your LoadFont() routine looks okay. NewFont() and OldFont() should definately use MK_FP(), but why you'd want a pointer to 010E::010C eludes me...
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:mogden
ID: 2741051
For SteveGTR:
(fontfile = fopen("pudgey.fnt", "rb")) == NULL;
---It says it can't open the file.

Help me quick, please.  I'm running out of points.

Cheers.

Colin:)
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 2741614
That means, that file pudgey.fnt not
found in you directory.
May be this one has other name
May be is placed in other directory(not
in yous). In this case you must
set full path as
fontfile = fopen("C:\\mydir\\pudgey.fnt", "rb");
0
 

Author Comment

by:mogden
ID: 2742639
Thanks heaps again, Steve.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question