Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » random data & access(file could not be opened)
random data & access [message #1746773] Fri, 04 November 2016 12:58 Go to next message
Massimo Mancini is currently offline Massimo ManciniFriend
Messages: 24
Registered: September 2016
Junior Member
Dear All.

I am here posting a new question for which I did not find other cases similar to mine.

In details, I am writing a code for which it is supposed to create a .dat file in order to use the program, in order to access and create data randomly.
I do suppose that at the console should ask me to enter some info in order to input my questioning.... or I do suppose that the file .dat need to be charged separately in a specific folder.

Isn't it?

I don't know how to figure out the error, even because when I lunch the program @ the console appear: " File could not be opened".

Any idea on what is going on?

I am using Windows 8.1 and the compiler MinGW compiler - Eclipse Mars.

Thank you for any advice.
Massimo

Re: random data & access [message #1746972 is a reply to message #1746773] Tue, 08 November 2016 08:55 Go to previous messageGo to next message
Massimo Mancini is currently offline Massimo ManciniFriend
Messages: 24
Registered: September 2016
Junior Member
I would add the code in order to be more explicit in my post.

Thanks for any comments.
Massimo



#include <stdio.h>

/* dichiarazione della struttura clientData */
struct clientData {
int acctNum; /* numero del conto */
char lastName[ 15 ]; /* cognome dell'intestatario del cont */
char firstName[ 10 ]; /* nome dell'intestatario del conto */
double balance; /* bilancio del conto */
}; /* fine della struttura clientData */

int main( void )
{
FILE *cfPtr; /* puntatore al file credit.dat */

/* crea clientData con informazioni di default */
struct clientData client = { 0, "", "", 0.0 };

/* fopen apre il file; se non riesce ad aprire il file, provoca l'uscita dal programma */
if ( ( cfPtr = fopen( "credit.dat", "rb+" ) ) == NULL ) {
printf( "File could not be opened.\n" );
fflush(stdout);

} /* fine del ramo if */
else {
/* chiede all'utente di specificare il numero del conto */
printf( "Enter account number"
" ( 1 to 100, 0 to end input )\n? " );
fflush(stdout);

scanf( "%d", &client.acctNum );

/* l'utente inserisce l'informazione che viene copiata nel file */
while ( client.acctNum != 0) {
/* l'utente inserisce il cognome, il nome ed il bilancio */
printf( "Enter lastname, firstname, balance\n? " );
fflush(stdout);

/* imposta il cognome, il nome ed il valore del bilancio del record */
fscanf( stdin, "%s%s%lf", client.lastName,
client.firstName, &client.balance );

/* trova la posizione nel file del record specificato dall'utente */
fseek( cfPtr, ( client.acctNum - 1 ) *
sizeof( struct clientData ), SEEK_SET );

/* scrive l'informazione specificata dall'utente nel file */
fwrite( &client, sizeof( struct clientData ), 1, cfPtr );

/* consente all'utente di specificare un altro numero di conto */
printf( "Enter account number\n? " );
fflush(stdout);

scanf( "%d", &client.acctNum );
} /* fine del comando while */

fclose(cfPtr); /* fclose chiude il file */
} /* fine del ramo else */

return 0;
}
Re: random data & access [message #1747049 is a reply to message #1746972] Tue, 08 November 2016 21:11 Go to previous messageGo to next message
David VavraFriend
Messages: 1415
Registered: October 2012
Senior Member
It likely means the file doesn't exist.
This forum is for addressing problems and issues arising from using CDT.
Questions about your own code are off topic.

Re: random data & access [message #1747080 is a reply to message #1747049] Wed, 09 November 2016 09:21 Go to previous messageGo to next message
Massimo Mancini is currently offline Massimo ManciniFriend
Messages: 24
Registered: September 2016
Junior Member
Sorry David and thanks for your reply. I am going to look at the proper forum. In fact I don't know in which folder need to be stored the file "client.dat".

Thanks anyway.
Massimo

Re: random data & access [message #1747081 is a reply to message #1747080] Wed, 09 November 2016 09:26 Go to previous messageGo to next message
Massimo Mancini is currently offline Massimo ManciniFriend
Messages: 24
Registered: September 2016
Junior Member
With your experience, which forum would you advice me? There are so many that I would make the same wrong posting once again ...

Re: random data & access [message #1747082 is a reply to message #1747081] Wed, 09 November 2016 09:28 Go to previous messageGo to next message
Massimo Mancini is currently offline Massimo ManciniFriend
Messages: 24
Registered: September 2016
Junior Member
if it is not a problem I'll post it at NEWCOMERS
Re: random data & access [message #1747085 is a reply to message #1747082] Wed, 09 November 2016 09:49 Go to previous messageGo to next message
David VavraFriend
Messages: 1415
Registered: October 2012
Senior Member
You could try stackoverflow.com but quite frankly you are asking for someone to debug your code.
That's generally OT at stackoverflow also.
You need to learn to do it yourself.

icon14.gif  Re: random data & access [message #1747396 is a reply to message #1747085] Mon, 14 November 2016 09:57 Go to previous message
Massimo Mancini is currently offline Massimo ManciniFriend
Messages: 24
Registered: September 2016
Junior Member
David Vavra wrote on Wed, 09 November 2016 09:49
You could try stackoverflow.com but quite frankly you are asking for someone to debug your code.
That's generally OT at stackoverflow also.
You need to learn to do it yourself.


Previous Topic:Update problem
Next Topic:cleaning Project fails
Goto Forum:
  


Current Time: Tue Jan 25 19:45:49 GMT 2022

Powered by FUDForum. Page generated in 0.02755 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top