Link to home
Start Free TrialLog in
Avatar of jerryof
jerryof

asked on

need help with c code

I'm trying to code in c for a PT630
I'm getting a bunch of type error in argument, any help would be greatly appreciated

char buffer[128];
char storage[128];
char string[100];
char CARNO[128];
char HEAT[32];
char COUNT[32];
char CURRENT[32];
int newtotal;
int idx;
int found;
int nxrec;
char wrt_total[16];

_countem()
{
nxrec =0;
nRec = 1;
nTotalRec = GetRecordNum("received.txt");
while ( nRec <= nTotalRec )
{  
strcpy(buffer, ReadRecord("RECEIVED.TXT",nRec, 0));  
GetFieldFromRecord(buffer, 1, ',', CARNO);      
GetFieldFromRecord(buffer, 3, ',', HEAT);
GetFieldFromRecord(buffer, 6, ',', COUNT);  

strcpy( string, CARNO );
strcat( string, HEAT );

idx = SearchFieldGr ( "TOTALS.TXT" , string,1,  2, ',', 1,0 , storage);
found = idx;
if (found)
{GetFieldFromRecord(storage, 2 , ',', CURRENT);
newtotal=atoi(&CURRENT)+atoi(&COUNT);
//itoa( newtotal,wrt_total,10);
sprintf(wrt_total, "%i", newtotal);

WriteField (  "TOTALS.TXT",  idx , 2 , "," ,  wrt_total );
}
else
{nxrec=nxrec+1;
WriteField (  "TOTALS.TXT", nxrec , 1 , "," , string );
WriteField (  "TOTALS.TXT",  nxrec , 2 , "," ,  COUNT );
nRec=nRec+1;
}
}
}

Avatar of mccarl
mccarl
Flag of Australia image

Well, we can't help too much without you posting the exact error messages or the rest of the code (ie. the code for all the functions that are called from the code above.

BUT, I can at least see that the line with the calls to atoi are incorrect. Remove the & so that the line looks like this...

 
newtotal=atoi(CURRENT)+atoi(COUNT);

Open in new window

Avatar of jerryof
jerryof

ASKER

takeing the ampersan out removed 2 of the errors
there are three remaining.
the compiler error just says "type error in argument"
there are no calls to anything outside this snipit
The routine is reading one file receive.txt and writing out to totals
it scans thru the received file and reads the railcar, the heat number, a count of the items unloaded
it then combines the railcar and heat number into a unique id.
it then searched for the unique id in the total.txt file.
if it finds the id it combines (adds together) the  value  stored in current which is a string
 and the value found in the received count which is a also a string
the fields have to be converted to int to perform the math and the
results are stored to newtotal which must be converted to string with sprintf
and stored to wrt_total
and stored as the second field in the record that was found with the searchfieldgr
if it was not found
a new record in written with the and the count


What are GetRecordNum, ReadRecord, SearchFieldGr, GetFieldFromRecord, WriteField? What are the types of their arguments?
> the compiler error just says "type error in argument"

It isn't giving you any line numbers?

> there are no calls to anything outside this snipit

As ozo asks, those calls are probably the ones that are failing, but without knowing what they do, in particular, what arguments they take, we can't really help further.
with three remaining errors, and 3 calls to WriteField, one might guess that they could be where the errors are,
but it's hard to be sure without knowing what arguments it is meant to take
ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jerryof

ASKER

The problem was with the  ","  double quote had to be single quote ','
I was thinking that. But there are times when we actually do write "," (e.g., when you want a selection of delimiters, but in this case there is only one). So, rather than guess, I thought I'd just make up prototypes consistent with your code. Glad you figured out the inconsistency.