the misterious case of the non-migrating function...
Hi,
I am trying to migrate my app from Windows to Linux (since C++ is sooooo portable...), and there is this one function that gives me the following error. I checked the sintax, itīs Ok. I searched through the entire C forums... and to avail. Here is the error:
Filetest.cpp: In function `int addCredit(char*, long int)':
Filetest.cpp:311: you are requesting the convertion from `int' to a non-escalar type `_G_fpos_t'
Filetest.cpp:341: no match for the operador `fpos_t& = int'
/usr/include/_G_config.h:27: candidates are: _G_fpos_t&
_G_fpos_t::operator=(const _G_fpos_t&)
Here is the code (basic stuff, I know)
Code:
int addCredit(char *number_in, long amount)
{
FILE *stream;
int count = 0;
fpos_t pos = 0;
long temp = 0;
char account_in[10];
char name_in[20];
char last_in[20];
long balance = 0; // length of the record is 66 bytes (get it from
// properties of the file after writing the first record)
printf("Buscando: %s\n",number_in);
// Attempt to open the file. If it returns NULL fails. exit with condition 1
if( (stream = fopen( FullFileName, "r+" )) == NULL )
return 1 ;
/* Cycle until end of file reached:or record found */
while( !feof( stream ) )
{
fscanf(stream,"%s %s %s %d\n",account_in, name_in, last_in, &balance);
if( ferror( stream ) )
{
perror( "Read error" );
break;
}
if ((strcmp(account_in,number_in)) == 0) // if they are identical
{
printf("Encontrado...");
// retroceder puntero para seņalar al registro correcto
pos = (66 * count); // length of record times nmbr of previous records
fsetpos( stream, &pos );
// ------------- modify amount and save it -----------------
temp = balance; // Restar del balance
balance = (temp + amount); // Actualizar el balance
fprintf(stream,"%10s %20s %20s %10ld\n",account_in, name_in, last_in, balance);
fclose(stream);
return 0;
}
// Count number of records read
count = count + 1;
}
printf("Registro no existe. Total registros: %d\n",count);
fclose(stream);
return 1;
any help would be greatly appreciated
Luis
you are closer on the first answer
I think that you may have gotten pretty close to the answer when you said something about the "typedef". Because as you can see, the error says something to the effect that the variables are incompatible, either here:
fpos_t pos = 0;
or here: pos = (66 * count);
The thing is, I need a variable so that I can back-up the file pointer to the beginning of the record, so that I can rewrite it.
And yes, I already tried compiling it with gcc.
Thanks for all the help.
Luis