Path: utzoo!attcan!uunet!husc6!think!ames!elroy!jplopto!dave
From: dave@jplopto.uucp (Dave Hayes)
Newsgroups: comp.sys.apollo
Subject: Re: How does ios_dir_$open work?
Message-ID: <8508@elroy.Jpl.Nasa.Gov>
Date: 17 Aug 88 23:39:23 GMT
References: <8808122122.AA14782@mailgw.cc.umich.edu> <8180@cup.portal.com>
Sender: uucp@elroy.Jpl.Nasa.Gov
Reply-To: dave@jplopto.UUCP (Dave Hayes)
Organization: Jet Propulsion Lab, Pasadena, CA
Lines: 36

> I don't understand why following codes don't work:
> #include 
> #include 
> main(argc, argv)
> int      argc;
> char    *argv;
> {
> char    *str1;
> strcpy(str1, argv[1]);
> }

This is not a problem with the apollo, but a problem with your understanding
of pointer syntax. Relax, it's a common mistake! The definition

     char *str1:

means "str1" is a POINTER to an array of characters. In other words, str1
is supposed to contain the address of a character array. But in this code
fragment, you have not assigned an address to "str1", so the variable contains
a "garbage" address. Therefore, when the program tries to run, it tries to copy 
the string pointed to by argv[1] to a non-existant character array. This is
why you get an "access violation". The way to fix this would be to define
str1 like this:

    char str1[255]; 
(or replace the 255 with some number more appropriate to your application)

so that there is an array defined for strcpy to copy into. 

I would suggest that you get a good book on basic C programming before you 
go any further. I don't know of any offhand, but there *are* some good books
out there that would help you avoid the more common C mistakes.

------===<<>>===------
dave%jplopto@jpl-mil.jpl.nasa.gov
{cit-vax,ames}!elroy!jplopto!dave