Solved

need help with c code

Posted on 2011-03-16
8
613 Views
Last Modified: 2012-05-11
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
Comment
Question by:jerryof
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 35

Expert Comment

by:mccarl
ID: 35152921
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
 

Author Comment

by:jerryof
ID: 35152997
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
 
LVL 84

Expert Comment

by:ozo
ID: 35153004
What are GetRecordNum, ReadRecord, SearchFieldGr, GetFieldFromRecord, WriteField? What are the types of their arguments?
0
 
LVL 35

Expert Comment

by:mccarl
ID: 35153090
> 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 84

Expert Comment

by:ozo
ID: 35153115
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
 
LVL 32

Accepted Solution

by:
phoffric earned 500 total points
ID: 35153563
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
 

Author Comment

by:jerryof
ID: 35157191
The problem was with the  ","  double quote had to be single quote ','
0
 
LVL 32

Expert Comment

by:phoffric
ID: 35157662
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now