[Search for users]
[Overall Top Noters]
[List of all Conferences]
[Download this site]
Title: | DECC |
Notice: | General DEC C discussions |
Moderator: | TLE::D_SMITH N TE |
|
Created: | Fri Nov 13 1992 |
Last Modified: | Fri Jun 06 1997 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 2212 |
Total number of notes: | 11045 |
2144.0. "char *String = char *String[] ?" by GIDDAY::SHCHIU () Wed Apr 09 1997 01:15
I have a customer site reports problem with following C program, Written
under VAXC V3.2. works and C is now upg to v5.5 on VAX/VMS , and also
on ALPHA/VMS installed DECC v5.5.
the code is generated run time error.
to make it works , "[]" is inserted after char Mystring.
Question :
1. Has strtok() been change since vaxc v3.2 ?
Is char Mystring = is valid expression for this case ??
rgds
/stanley
ty doeswork.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main ()
{
/******************* Code that does work with the addition of [ ]. */
char Mystring[]="This is the ,1-Jan-1997 00:01:00,67,123,1.1,1.2";
char *StartString;
int Index;
printf ("%s, Length=%d \n", Mystring,strlen(Mystring));
StartString= strtok(Mystring,",");
Index=0;
while (StartString != NULL)
{
Index++;
printf ("%s Length=%d \n", StartString,strlen(StartString));
if (Index >=3)
{
printf(" Index is %d \n",Index);
printf(" Conversion is %d \n",atol(StartString));
};
StartString= strtok(NULL,",");
};
}
$
----------------------
$ ty doesnotwork.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main ()
{
/******************* Code that doesn't work is the following line. */
char *Mystring="This is the ,1-Jan-1997 00:01:00,67,123,1.1,1.2";
char *StartString;
int Index;
printf ("%s, Length=%d \n", Mystring,strlen(Mystring));
StartString= strtok(Mystring,",");
Index=0;
while (StartString != NULL)
{
Index++;
printf ("%s Length=%d \n", StartString,strlen(StartString));
if (Index >=3)
{
printf(" Index is %d \n",Index);
printf(" Conversion is %d \n",atol(StartString));
};
StartString= strtok(NULL,",");
};
}
$
$ cc/ver/noobj nl:
DEC C V5.3-006 on OpenVMS Alpha V6.2
$
$ run doesnotwork
This is the ,1-Jan-1997 00:01:00,67,123,1.1,1.2, Length=47
%SYSTEM-F-ACCVIO, access violation, reason mask=04, virtual address=00010124, PC
=805ADEAC, PS=0000001B
%TRACE-F-TRACEBACK, symbolic stack dump follows
Image Name Module Name Routine Name Line Number rel PC abs PC
0 805ADEAC 805ADEAC
DOESNOTWORK DOESNOTWORK main 1965 00000114 00020114
DOESNOTWORK DOESNOTWORK __main 0 00000064 00020064
0 832D4170 832D4170
$
$ run doeswork
This is the ,1-Jan-1997 00:01:00,67,123,1.1,1.2, Length=47
This is the Length=12
1-Jan-1997 00:01:00 Length=19
67 Length=2
Index is 3
Conversion is 67
123 Length=3
Index is 4
Conversion is 123
1.1 Length=3
Index is 5
Conversion is 1
1.2 Length=3
Index is 6
Conversion is 1
$
---------------------------
Ripper_> cc/noobj/ver nl:
DEC C V5.2-003 on OpenVMS VAX V6.1
Ripper_>
Ripper_> run doesnotwork
This is the ,1-Jan-1997 00:01:00,67,123,1.1,1.2, Length=47
%SYSTEM-F-ACCVIO, access violation, reason mask=04, virtual address=0000020C, PC
=000836F4, PSL=03C00000
%TRACE-F-TRACEBACK, symbolic stack dump follows
module name routine name line rel PC abs PC
000836F4 000836F4
DOESNOTWORK main 1963 00000041 000002B9
Ripper_>
ipper_> run doeswork
This is the ,1-Jan-1997 00:01:00,67,123,1.1,1.2, Length=47
This is the Length=12
1-Jan-1997 00:01:00 Length=19
67 Length=2
Index is 3
Conversion is 67
123 Length=3
Index is 4
Conversion is 123
1.1 Length=3
Index is 5
Conversion is 1
1.2 Length=3
Index is 6
Conversion is 1
Ripper_>
T.R | Title | User | Personal Name | Date | Lines |
---|
2144.1 | Really a user error, but you can make DECC swallow it | WIBBIN::NOYCE | Pulling weeds, pickin' stones | Wed Apr 09 1997 09:44 | 15 |
| > char Mystring[]="This is the ,1-Jan-1997 00:01:00,67,123,1.1,1.2";
This creates a 48-byte variable, initialized to the value shown here.
> char *Mystring="This is the ,1-Jan-1997 00:01:00,67,123,1.1,1.2";
This creates a pointer to a 48-byte constant.
> StartString= strtok(Mystring,",");
This tries to replace the first "," with a null.
In the case that works, you're storing into a variable -- no problem.
In the case that doesn't work, you're trying to store into a constant,
and DEC C doesn't allow that by default. VAX C did allow it, and you
can get DEC C to allow it by using a compile qualifier
/ASSUME=WRITABLE_STRING_LITERALS. (Compiling with /STANDARD=VAXC turns
on this switch for you.)
|
2144.2 | thanks for the comments. | GIDDAY::SHCHIU | | Wed Apr 09 1997 20:26 | 2 |
|
|