SCOUG-HELP Mailing List Archives
Return to [ 10 | 
February | 
2002 ]
 >> Next Message >>
 
 
 
Content Type:   text/plain 
=====================================================  
If you are responding to someone asking for help who  
may not be a member of this list, be sure to use the  
REPLY TO ALL feature of your email program.  
=====================================================  
 
Thanks, Steven. Your instructions work! Next question, if you would.  
Below, please find a simple source code in which I created a structure  
called "TEST" and declared and initialized one instance of it (MyTest).  
Now, I'm having trouble accessing member elements within this structure  
instance to change their values. I've looked at the Watcom documentation  
and, in lines 17-19, tried to implement what it says (for clarity I've  
shown some of the line numbers in the source code as "#:" on the left  
side of the line). I also tried what my SAMS "Teach Yourself C in 21  
Days" book says (line 20 of the source code). However, the compiler  
gives me an error either way (see error logfile output, below). Any  
suggestions for this problem?? Thanks for your help.  
 
 
Test.c source code:  
_____________________________________________________________________________________  
1:/*Begin include statements*/  
2:#include   
3:#include   
4:/*End include statements*/  
 
/*Begin variable declarations*/  
8:FILE *fp;  
9:char *ReadFileName = "C:\\LaTeX\\Academic_Press\\doi.html";  
10:char *Mode = "rt";  
11:char *FileName;  
12:typedef struct {  
13:	int AnyNumber;  
14:	char LastName[256];  
15:} TEST;  
16:TEST MyTest = {29,"Motin"};  
17:TEST *p_MyTest;  
18:p_MyTest = &MyTest;  
19:(*p_MyTest).AnyNumber = 30;  
20:MyTest.AnyNumber = 30;  
21:TEST *FILEREAD(char *FileName);	/*Profile for the FILEREAD utility  
function*/  
 
/*struct fread ReturnResult;*/  
/*ReturnResult.FileOpenRC = 3;*/  
 
/*End variable declarations*/  
 
 
 
main()  
{  
	if( (fp = fopen(ReadFileName, Mode)) != NULL )  
	{  
		printf("\n The file, %s, has been opened.", ReadFileName);  
		fclose(fp);  
	}  
	else  
		printf("\n The file, %s, cannot be opened.", ReadFileName);  
	return(0);  
}  
_____________________________________________________________________________________  
 
 
 
error logfile output:  
_____________________________________________________________________________________  
test.c(18): Error! E1129: Type does not agree with previous definition  
of 'p_MyTest'  
test.c(18): Warning! W102: Type mismatch (warning)  
test.c(19): Error! E1129: Type does not agree with previous definition  
of 'p_MyTest'  
test.c(19): Error! E1009: Expecting ';' but found '.'  
test.c(19): Error! E1061: Expecting data or function declaration, but  
found '.'  
test.c(20): Error! E1129: Type does not agree with previous definition  
of 'MyTest'  
test.c(20): Error! E1009: Expecting ';' but found '.'  
test.c(20): Error! E1061: Expecting data or function declaration, but  
found '.'  
test.c(20): Error! E1068: Variable 'AnyNumber' already initialized  
 
 
HCMotin  
_____________________________________________________________________________________  
 
Steven Levine wrote:  
>   
> =====================================================  
> If you are responding to someone asking for help who  
> may not be a member of this list, be sure to use the  
> REPLY TO ALL feature of your email program.  
> =====================================================  
>   
> In <3C65D191.54A991DB@attglobal.net>, on 02/09/02  
>    at 05:49 PM, Harry Chris Motin  said:  
>   
> >char ReadFileName;  
> >ReadFileName = "Harry";  
>   
> This should be either:  
>   
>   char *ReadFileName = "Harry";    // Pointer to character initialize to  
> point to a string  
>   
> or  
>   
>   char ReadFileName[] = "Harry";   // Array of 6 characters initialized to  
> ...  
>   
> or  
>   
>   char ReadFileName[20] = "Harry";   // Array of 20 characters initialized  
> to ...  
>   
> depending on exactly how you want to use ReadFileName.  The first two  
> forms are fine if the string is a constant.  The latter is better if you  
> are setting a default which you might override.  
>   
> What you defined was a character, not an array of characters.  
>   
> >The compiler error message is almost as if Watcom does not accept the  
> >"char" keyword as a valid variable declaration. Can anyone help me here?  
>   
> Not quite:  
>   
>   char aChar = 'a';                  // A character initialized to the  
> letter a  
>   
>   printf("aChar is set to '%c'\n", aChar);  
>   
> Does that clarify things?  
>   
> Steven  
>   
> --  
> ---------------------------------------------------------------------  
> "Steven Levine"   MR2/ICE 2.31a #10183 Warp4/FP15/14.085_W4  
> www.scoug.com irc.webbnet.org #scoug (Wed 7pm PST)  
> ---------------------------------------------------------------------  
>   
> =====================================================  
>   
> To unsubscribe from this list, send an email message  
> to "steward@scoug.com". In the body of the message,  
> put the command "unsubscribe scoug-help".  
>   
> For problems, contact the list owner at  
> "rollin@scoug.com".  
>   
> =====================================================  
=====================================================  
 
To unsubscribe from this list, send an email message  
to "steward@scoug.com". In the body of the message,  
put the command "unsubscribe scoug-help".  
 
For problems, contact the list owner at  
"rollin@scoug.com".  
 
=====================================================  
 
  
 >> Next Message >>
Return to [ 10 | 
February | 
2002 ] 
  
  
The Southern California OS/2 User Group
 P.O. Box 26904
 Santa Ana, CA  92799-6904, USA
Copyright 2001 the Southern California OS/2 User Group.  ALL RIGHTS 
RESERVED. 
 
SCOUG, Warp Expo West, and Warpfest are trademarks of the Southern California OS/2 User Group.
OS/2, Workplace Shell, and IBM are registered trademarks of International 
Business Machines Corporation.
All other trademarks remain the property of their respective owners.
 
   |