Hello everyone...
Anybody can help me on this question, please?
i´ve this code in my application:
/*for Card creation*/
typedef struct card
{
etc,etc
} Card;
typedef Card *PtrCrt;
/*For trans creation*/
typedef struct trans
{
etc,etc
} Trans;
typedef Trans *PtrTrans;
I need to calculate the Balance of every card and how put this verification
in one function?! 13 1974
"Maria Mela" <h4***@netvisao .ptwrote in message
news:ne******** ************@ne wsfront4.netvis ao.pt...
Hello everyone...
Anybody can help me on this question, please?
i´ve this code in my application:
/*for Card creation*/
typedef struct card
{
etc,etc
} Card;
typedef Card *PtrCrt;
/*For trans creation*/
typedef struct trans
{
etc,etc
} Trans;
typedef Trans *PtrTrans;
I need to calculate the Balance of every card and how put this
verification in one function?!
int balance(const Card *c)
{
int result;
/* calculate */
return result;
}
int main(void)
{
Card c = { /* etc. */ };
printf("balance = %d\n", balance(&c));
return 0;
}
For more specific advice, ask more specific questions.
-Mike
Maria Mela wrote:
Hello everyone...
Anybody can help me on this question, please?
i´ve this code in my application:
/*for Card creation*/
typedef struct card
{
etc,etc
} Card;
typedef Card *PtrCrt;
/*For trans creation*/
typedef struct trans
{
etc,etc
} Trans;
typedef Trans *PtrTrans;
I need to calculate the Balance of every card and how put this verification
in one function?!
Please be more specific. What is the balance of a card? What do you
need to verify? How are you representing the aggregation of cards?
As an array? A singly-linked list? Many singly-linked lists?
P.S. http://www.nls.net/mp/413/sea.ZIP
Self-expanding arrays. (This is the code your college professor
warned you about.) :) :) :)
Thks for your help... But to be more specific here´s one part of my code...
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <alloc.h>
#include <string.h>
typedef enum observations
{
Item1=1,Item2,I tem3,Item4,Item 5
}Observations;
typedef enum trans_type
{
CRG=1, DBT,TRF
}Trans_type;
typedef enum utente
{
Student=1, Functionary ,Professor
}Utente;
typedef struct data
{
int day, month, year;
}Data;
typedef struct card
{
int num_card;
char name[255];
Utente utente;
Data data;
float balance;
char morada[60];
struct card *next;
} Card;
typedef Card *PtrCrt;
typedef struct transaccions
{
int codigo;
char nome[60];
Data data;
Trans_tipo trans_tipo;
float montante,crg;
Observacoes observacoes;
char local_treinos[60];
char nome_treinador[60];
struct trans *next;
PtrCrt p_cartao;
} Trans;
typedef Trans *PtrTrans;
/*------------------------Functions------------------------*/
void Insert_Card (PtrCrt *lista);
void Change_Card (PtrCrt *lista);
void Remove_Card (PtrCrt *lista);
void View_Cards (PtrCrt *lista);
void Delet_Cards (PtrCrt *lista);
int View_if_Cards (PtrCrt *lista, int cod, int ver);
void Insert_Trans (PtrTrans *lista);
void Remove_Trans (PtrTrans *lista);
void View_Trans (PtrTrans *lista);
void Delet_Trans (PtrTrans *lista);
int View_if_Trans (PtrTrans *lista, int cod, int ver);
void Error (char *msg);
PtrCrt Adress_Card (PtrCrt *lista, int cod);
PtrTrans Adress_Trans (PtrTrans *lista, int cod);
void View_Cards_Asso c (PtrCrt *lista);
void View_Card_Trans (PtrTrans *lista);
void Menu_Cards (void);
void Menu_Transaccio ns (void);
void Menu_Listall (void);
I need to calculate the Balance of every card in all new transaccions and
how put this verification
in one function?!
It´s better create one more strcut for movements (transaccions) cards?
I´m confused...
"Jeff Mullen" <41*@nls.netesc reveu na mensagem
news:a3******** *************** **@ALLTEL.NET.. .
Maria Mela wrote:
>Hello everyone... Anybody can help me on this question, please? i´ve this code in my application:
/*for Card creation*/ typedef struct card { etc,etc } Card; typedef Card *PtrCrt;
/*For trans creation*/ typedef struct trans { etc,etc } Trans; typedef Trans *PtrTrans;
I need to calculate the Balance of every card and how put this verification in one function?!
Please be more specific. What is the balance of a card? What do you
need to verify? How are you representing the aggregation of cards?
As an array? A singly-linked list? Many singly-linked lists?
P.S.
http://www.nls.net/mp/413/sea.ZIP
Self-expanding arrays. (This is the code your college professor
warned you about.) :) :) :)
Maria Mela wrote:
>
Thks for your help... But to be more specific here´s one part of my code...
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <alloc.h>
#include <string.h>
Please don't top-post. Your answer belongs after (or intermixed
with) the material to which you reply, after snipping. See the
references in my sig. below.
The above code is off-topic here, since conio.h and alloc.h are
non-standard.
--
Some informative links:
<http://www.catb.org/~esr/faqs/smart-questions.html>
<http://www.caliburn.nl/topposting.html >
<http://www.netmeister. org/news/learn2quote.htm l>
<http://cfaj.freeshell. org/google/ (taming google)
<http://members.fortune city.com/nnqweb/ (newusers)
Jeff Mullen wrote, On 22/01/07 07:47:
<snip>
P.S.
http://www.nls.net/mp/413/sea.ZIP
Self-expanding arrays. (This is the code your college professor
warned you about.) :) :) :)
Extracts from the code in the archive above...
from sea.h:
| #ifndef _SEA_H_
|
| #define _SEA_H_
Names starting with an underscore followed by an upper case letter are
reserved for use by the implementation. Don't do that.
from sea.c:
| else if ((ST_sea = malloc(sizeof(S EA))) == NULL)
Better to use:
else if ((ST_sea = malloc(sizeof *ST_sea))) == NULL)
Then you do not have to worry about getting the type correct. Very
useful if the type ever gets changed.
| {
| ST_sea = NULL;
| } /* if */
Isn't assigning NULL to ST_sea a bit pointless when you have just found
that it is equal to NULL? This smells like it has not been properly
thought out to me.
| if ((ST_sea->V_items = realloc(ST_sea->V_items, ST_sea->i_num_alloc
| * ST_sea->i_item_size) ) == NULL)
If realloc fails here you have just lost your pointer to the old, still
valid memory. You should always assign the result of realloc to a
temporary variable for testing and then, only if realloc succeeded
overwrite your old pointer.
Also you use something called WITHIN the definition of which is not
provided. Possibly it is defined in friendly.h, but you don't provide
that in the ZIP you provide that in the ZIP you pointed people at.
I've not looked any further because it currently is not in a compilable
state.
--
Flash Gordon
CBFalconer said:
Maria Mela wrote:
>> Thks for your help... But to be more specific here´s one part of my code...
#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <alloc.h> #include <string.h>
<snip>
The above code is off-topic here, since conio.h and alloc.h are
non-standard.
I don't entirely agree, or at least I think your explanation is incomplete.
It is entirely possible that conio.h and alloc.h are user-defined headers
whose source the OP unaccountably forgot to include, which might well be
written entirely in ISO C.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at the above domain, - www.
Maria Mela wrote:
Thks for your help... But to be more specific here´s one part of my code...
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <alloc.h>
#include <string.h>
typedef enum observations
{
Item1=1,Item2,I tem3,Item4,Item 5
}Observations;
typedef enum trans_type
{
CRG=1, DBT,TRF
}Trans_type;
typedef enum utente
{
Student=1, Functionary ,Professor
}Utente;
typedef struct data
{
int day, month, year;
}Data;
typedef struct card
{
int num_card;
char name[255];
Utente utente;
Data data;
float balance;
char morada[60];
struct card *next;
} Card;
typedef Card *PtrCrt;
typedef struct transaccions
{
int codigo;
char nome[60];
Data data;
Trans_tipo trans_tipo;
float montante,crg;
Observacoes observacoes;
char local_treinos[60];
char nome_treinador[60];
struct trans *next;
PtrCrt p_cartao;
} Trans;
typedef Trans *PtrTrans;
/*------------------------Functions------------------------*/
void Insert_Card (PtrCrt *lista);
void Change_Card (PtrCrt *lista);
void Remove_Card (PtrCrt *lista);
void View_Cards (PtrCrt *lista);
void Delet_Cards (PtrCrt *lista);
int View_if_Cards (PtrCrt *lista, int cod, int ver);
void Insert_Trans (PtrTrans *lista);
void Remove_Trans (PtrTrans *lista);
void View_Trans (PtrTrans *lista);
void Delet_Trans (PtrTrans *lista);
int View_if_Trans (PtrTrans *lista, int cod, int ver);
void Error (char *msg);
PtrCrt Adress_Card (PtrCrt *lista, int cod);
PtrTrans Adress_Trans (PtrTrans *lista, int cod);
void View_Cards_Asso c (PtrCrt *lista);
void View_Card_Trans (PtrTrans *lista);
void Menu_Cards (void);
void Menu_Transaccio ns (void);
void Menu_Listall (void);
I need to calculate the Balance of every card in all new transaccions and
how put this verification
in one function?!
It´s better create one more strcut for movements (transaccions) cards?
I´m confused...
"Jeff Mullen" <41*@nls.netesc reveu na mensagem
news:a3******** *************** **@ALLTEL.NET.. .
>Maria Mela wrote:
>>Hello everyone... Anybody can help me on this question, please? i´ve this code in my application:
/*for Card creation*/ typedef struct card { etc,etc } Card; typedef Card *PtrCrt;
/*For trans creation*/ typedef struct trans { etc,etc } Trans; typedef Trans *PtrTrans;
I need to calculate the Balance of every card and how put this verificatio n in one function?!
Please be more specific. What is the balance of a card? What do you need to verify? How are you representing the aggregation of cards? As an array? A singly-linked list? Many singly-linked lists?
P.S.
http://www.nls.net/mp/413/sea.ZIP
Self-expanding arrays. (This is the code your college professor warned you about.) :) :) :)
Thank you for the additional information, but you still didn't answer
the first question I asked: what is the "balance" of a card?
ASSUMING that you are storing your cards in a singly-linked list,
and that you have a header pointer around somewhere, you can do
your computations using a FOR loop. Assuming that the header
pointer, called "hand," is in your code somewhere, and that you
have a function called computer_balanc e that takes a pointer to
card as its argument and computes the balance for that card:
Card *scrutiny;
int balance = 0;
for (scrutiny = hand; scrutiny != NULL; scrutiny = scrutiny->next)
{
balance += compute_balance (scrutiny);
} /* for */
should be close to what you're asking for, as I understand it
based on the fragmentary information that you have given.
Flash Gordon wrote:
Jeff Mullen wrote, On 22/01/07 07:47:
<snip>
>P.S.
http://www.nls.net/mp/413/sea.ZIP
Self-expanding arrays. (This is the code your college professor warned you about.) :) :) :)
Extracts from the code in the archive above...
from sea.h:
| #ifndef _SEA_H_
|
| #define _SEA_H_
Names starting with an underscore followed by an upper case letter are
reserved for use by the implementation. Don't do that.
from sea.c:
| else if ((ST_sea = malloc(sizeof(S EA))) == NULL)
Better to use:
else if ((ST_sea = malloc(sizeof *ST_sea))) == NULL)
Then you do not have to worry about getting the type correct. Very
useful if the type ever gets changed.
| {
| ST_sea = NULL;
| } /* if */
Isn't assigning NULL to ST_sea a bit pointless when you have just found
that it is equal to NULL? This smells like it has not been properly
thought out to me.
| if ((ST_sea->V_items = realloc(ST_sea->V_items,
ST_sea->i_num_alloc
| * ST_sea->i_item_size) ) == NULL)
If realloc fails here you have just lost your pointer to the old, still
valid memory. You should always assign the result of realloc to a
temporary variable for testing and then, only if realloc succeeded
overwrite your old pointer.
Also you use something called WITHIN the definition of which is not
provided. Possibly it is defined in friendly.h, but you don't provide
that in the ZIP you provide that in the ZIP you pointed people at.
I've not looked any further because it currently is not in a compilable
state.
Thank you for looking my code over. I hope that all the people
whom you provide with unsolicited reviews will be as forthright,
and in as much a position to make changes regarding your constructive
criticism, as I am.
As a matter of internet etiquette, you should have sent me a private
email about this--not because the message might air some "dirty
laundry" of mine (I don't care about that if it improves the code),
but because, as I am rather busy, the message on a usenet list might
expire before I can get back to it. Thankfully, that was not the
case this time. You should also consider asking people whether
they would like their code reviewed when they do not explicitly
request this service. As I pointed out, I appreciate your efforts,
but you should be more sensitive to the possibility of other points
of view.
Jeff
Jeff Mullen <41*@nls.netwri tes:
As a matter of internet etiquette, you should have sent me a private
email about this--not because the message might air some "dirty
laundry" of mine (I don't care about that if it improves the code),
but because, as I am rather busy, the message on a usenet list might
expire before I can get back to it.
It's not normal practice to send email in response to a Usenet
article, unless the email is not in line with the topic of the
group. Generally it's people who view Usenet as "write-only" who
ask for email replies.
You should also consider asking people whether they would like
their code reviewed when they do not explicitly request this
service.
It's also not normal practice to ask about this in comp.lang.c.
Generally, we assume that if you're posting code here, or posting
about code here, you'd like us to look it over.
--
"To get the best out of this book, I strongly recommend that you read it."
--Richard Heathfield This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Greg |
last post by:
On my report I want to have an opening balance signifying all transactions
up to the month selected
and detailed transactions for the month selected
and then a closing blance.
I'm perpelexed how to do this Anyone knows how the banks do it with
statement formatting?
suggestions, ideas welcome.
|
by: bobdydd |
last post by:
Hi Guys Can anyone help
I am trying to find a way to implement a running balance that will
re-calculate if the date order is changed, or if an earlier record is
changed like you might want to do during a bank statement reconcile.
I am using the following fields
Date|Payment|Deposit|Running_Balance (tblTransactions)
|
by: RobcPettit |
last post by:
Hi, after reading up, c# doesnt appear to use gloal variables. Alot of
post advise against them also. So Im wondering how to get around this.
Im trying to do a calculation, retain the result, do another
calculation then add the result to my retained value etc. my values:
Im backing then laying horses. So I back first, say with a return of
£20...
|
by: mauking |
last post by:
Hello Everyone,
Im a certified public accountant here in the Philippines. Im using microsoft access 2000 and 2003 running in a Windows XP environment.
Im having a problem of how to calculate a running balance using a query coming from two tables.
This is my problem. I have two tables (Sales and Collections), with these table I wanted to...
|
by: Paul H |
last post by:
I have a transactions table and a balance table that look something
like this:
tblTransactions
TransactionID (PK Autonumber)
ClientID
TransactionDate
TransactionAmount (currency field, values must be >0)
CRDR (indicates whether the transaction is a (credit or debit)
StatementDate (Date stamp applied when the “Statement” report is run)
| |
by: dustonheaven |
last post by:
I need to calculate running balance on data containing Null, which is sorted by few columns.
As example below, Clr is sorted by Null Desc, then by date, then just by ID.
So far, I just come out with this...
SELECT tr1.Clr, tr1.ID, tr1.Date, tr1.Acc, tr1.Dbt, tr1.Cdt, (SELECT SUM(Nz(tr2.Dbt) - Nz(tr2.Cdt)) FROM tbl00 AS tr2 WHERE (tr2.Acc =...
|
by: maxx233 |
last post by:
I need to figure out a way to generate a report to find customers in our DB that have unused credits on their account so we can void them out periodically - we manually assign them credits, they make purchases, but if they don't use the full balance of the credits in 24 hours we can negate the leftover (it's a promotional thing.)
There's two...
|
by: darendaren88 |
last post by:
I have created this table:
mysql> describe acount;
+----------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------+------+-----+---------+----------------+
| uniqueID | bigint(20) | NO | PRI | NULL | auto_increment |
| amount |...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |