Hello All,

I have a requirement as follows.

I am writing a software to compute invoice .

The program will get the user details and it will autogenerate a INVOICE NUMBER.

So in order to auto generate the INVOICE NUMBER, i tried to use file concept.

I save a integer in a file. Then i read the content of the file and get the integer . I increment the value by 1 and use it as INVOICE NUMBER. Then I save the new INTEGER in the same file.

i used the getw() and putw() functions. But it genrates exception.

The code is getting compiled, but It couldn't execute.

Please help me what I should do.

Or is there any other method to have this AUTO GENERATION of my INVOICE NUMBER.

--
Rigidboss

Well posting your actual code (not a description of a couple of functions you used, and "it crashed") would go a long way to helping you.

Hello

Here is my code.

FILE *fp; 
fp=fopen(“test”,”r”);
int a = getw(fp);
printf("%d",a);
fclose(fp);

The above code is getting complied. But while executing, it is generating exception.

Is there anyother way to generate auto number in ascending order for my invoice software ??? is so please let me know.

--

Rigidboss

Where is your

if ( fp != NULL ) {
  // yay!, read the file
} else {
  // WTF?!
}

If the open fails, and you try to read it, then you're looking down the barrel of an exception.

Where is your

if ( fp != NULL ) {
  // yay!, read the file
} else {
  // WTF?!
}

If the open fails, and you try to read it, then you're looking down the barrel of an exception.

But Salem, I do have a file test. I created a file and then only am executing this code. What is the need for an else case ????

Well apparently, you're probably in a different working directory to the one you think you are in.

> What is the need for an else case ?
Either way, failing to add error checking code to something like file open, even when you claim "but the file is there", is just plain bad programming IMO.

I totally agree with you salem.

I did wat you directed me. Program shows the same exception

The thing what I noticed it, It is entering to my If case, but then it is throwing exception in getw() function.

When i attempted to debug it, It showed me some low level definition of this getw().

Please help me now. It shows as "applicationexception in <Memory address> "

--

Rigidboss

You're dereferencing an illegal pointer.
Posting the complete code which shows this problem may be of some use (if it's not too long).

But if it lacks the basic error checking I've pointed out above, and that appears to be the problem, I won't be a happy bunny, and I won't be helping you again.

Hello All,

I have a requirement as follows.

I am writing a software to compute invoice .

The program will get the user details and it will autogenerate a INVOICE NUMBER.

So in order to auto generate the INVOICE NUMBER, i tried to use file concept.

I save a integer in a file. Then i read the content of the file and get the integer . I increment the value by 1 and use it as INVOICE NUMBER. Then I save the new INTEGER in the same file.

i used the getw() and putw() functions. But it genrates exception.

The code is getting compiled, but It couldn't execute.

Please help me what I should do.

Or is there any other method to have this AUTO GENERATION of my INVOICE NUMBER.

--
Rigidboss

i dont really get what u want to know, is that u want to know how to write a program using file or wat ..... pls make me clear.??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.