Problems at C
Bob Funchess
S090726 at UMRVMA.UMR.EDU
Wed Dec 27 21:03:29 AEST 1989
I have been trying to figure out what is wrong with this piece of code...
unsuccesfully. Could someone point me in the right direction or suggest
a substitute?
#include <bsd/strings.h>
#include "kernel.h"
/*
** Open file for read/write or die trying
*/
static FILE *Do_fopen(char *name, char *mode)
{
FILE *file;
if (*name == '-' && !name[1])
return *mode == 'w' ? stdout : stdin;
if (!(file = fopen(name,mode))) {
perror(name);
(void)fprintf(stderr, "Unable to open file for %s\n",
*mode == 'w' ? "write" : "read");
exit(1);
}
return file;
}
static void make_reset(int argc, char *argv[])
{
FILE *In, *Out;
int *ip;
int i, blob[10000];
char buff[128];
if (argc < 3) {
(void)fprintf(stderr, "Usage error\n");
exit(1);
}
In = Do_fopen(argv[1], "r");
Out = Do_fopen(argv[2], "w");
/* Read thru object file, ignoring nonnumeric lines and collecting */
/* others into blob[] for write to output file... */
for (ip = blob, i = 0; fgets(buff, sizeof(buff), In); ) {
if (*buff == '-' || isdigit(*buff)) >>>>>> Here is the problem...
*ip++ = ((i++ & 0x03) == 2) ? flags(buff) : atoi(buff);
}
sec_write(Out, blob, 0, ip - blob);
(void)fclose(In);
(void)fclose(Out);
exit(0);
}
The problem is that at the location indicated I get a segmentation fault.
I also tried replacing that line with
firstin = *buff;
and
firstin = buff(1)
< Bob | S090726 at UMRVMA.UMR.EDU | Funchess >
The 'S' stands for student. Think the university shares MY opinions?
More information about the Comp.sys.sgi
mailing list