• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 638
  • Last Modified:

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;
}
}
}

0
jerryof
Asked:
jerryof
  • 2
  • 2
  • 2
  • +1
1 Solution
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
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

0
 
jerryofAuthor Commented:
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


0
 
ozoCommented:
What are GetRecordNum, ReadRecord, SearchFieldGr, GetFieldFromRecord, WriteField? What are the types of their arguments?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
> 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.
0
 
ozoCommented:
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
0
 
phoffricCommented:
As I understand it, this question is about compiler error and warning messages.

I modified the atoi line per mccarl's comment. I added extra declarations and got this to compile with no warning/errors.

In project -> properties -> C/C++ -> Preprocessor, I appended ";_CRT_SECURE_NO_WARNINGS" to look like:
    _MBCS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS
to remove warnings

I also changed the name of your function removing the leading underscore, as that is reserved by Microsoft.
#include <string.h>
#include <stdio.h>
#include <stdlib.h>

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];
int nTotalRec, nRec;

int GetRecordNum(char *);
char * ReadRecord(char*,int,int );
void GetFieldFromRecord(char*, int, char, char*);
int SearchFieldGr(char*, char*, int, int, char, int, int, char*);
void WriteField( char*, int, int, char*, char*);

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

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];
int nTotalRec, nRec;

int GetRecordNum(char *);
char * ReadRecord(char*,int,int );
void GetFieldFromRecord(char*, int, char, char*);
int SearchFieldGr(char*, char*, int, int, char, int, int, char*);
void WriteField( char*, int, int, char*, char*);

int 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;
      }
   }
   return nRec;
}

Open in new window

0
 
jerryofAuthor Commented:
The problem was with the  ","  double quote had to be single quote ','
0
 
phoffricCommented:
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.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now