?
Solved

need help with c code

Posted on 2011-03-16
8
Medium Priority
?
635 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 36

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
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.

 
LVL 36

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
 
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 2000 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

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Suggested Courses

770 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