I want to print a return value of 1 or 0 or some other number in a c program to the screen.
Code:
if ( readFile() != 0 )
{
fprintf(stderr, "Unable to read input file!\n");
program_exit(E_FILES_READ);
}
printf("equals zero \n");
int readFile()
{
char revAccName[51];
char custSortCode[7];
char custAccNum[9];
char custAccName[19];
char amount[12];
char date[9];
char id1[21];
char id2[21];
char id3[21];
char reason[2];
char record[292];
cur = &head;
for(;;)
{
if ( !fgets(record, 291, inFile) )
break;
if (strlen(record) < 101)
return 1;
strncpy(revAccName, &record[5], 50);
revAccName[50] = 0;
strncpy(custSortCode, &record[55], 6);
custSortCode[6] = 0;
strncpy(custAccNum, &record[61], 8);
custAccNum[8] = 0;
strncpy(custAccName, &record[69], 18);
custAccName[18] = 0;
strncpy(amount, &record[87], 11);
amount[11] = 0;
strncpy(id1, &record[106], 20);
id1[20] = 0;
strncpy(id2, &record[126], 20);
id2[20] = 0;
strncpy(id3, &record[146], 20);
id3[20] = 0;
strncpy(reason, &record[166], 1);
reason[1] = 0;
/* Allocate space for the record and hook it up to list. */
*cur = (unpaids_t *)calloc(1, sizeof(unpaids_t));
if (!*cur)
return 1;
strcpy((*cur)->revAccName, &revAccName[strspn(revAccName," ")]);
strcpy((*cur)->custSortCode, &custSortCode[strspn(custSortCode," ")]);
strcpy((*cur)->custAccNum, &custAccNum[strspn(custAccNum," ")]);
strcpy((*cur)->custAccName, &custAccName[strspn(custAccName," ")]);
strcpy((*cur)->amount, &amount[strspn(amount," ")]);
strcpy((*cur)->id1, &id1[strspn(id1," ")]);
strcpy((*cur)->id2, &id2[strspn(id2," ")]);
strcpy((*cur)->id3, &id3[strspn(id3," ")]);
strcpy((*cur)->reason, &reason[strspn(reason," ")]);
(*cur)->next = NULL;
cur = &((*cur)->next);
}
}
The program originally worked like this.
Since moving to a new unix box it fails. Do we think the version of the OS needs to explicitly have a return 0;
It's not my code it's someone elses and I am loathe to change anything because it has always worked before.
Sun 5.9 original
SunOS 5.10 now.
Adding in the return 0 fixes it. But the program does work on 5.9
I would also maybe like to print the return code any suggestions ?