|
Dear All,
The code below is C Programming that i wrote and is working but I am having problem in reading any records I am saving into text File called "MY FILE".Also anytime to ADD NEW RECORD in my switch case selection,the initial record that was in the is been deleted automatically.Did any one know what is wrong.I can figure it out,i have been tried debugging but all to no avail.I will appreciate your ideas.Thanks
***********************************************************'''''****
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 10
#define Income_type 8
#define Expense_type 7
typedef struct{
int day;
int month;
int year;
}Date_of_transaction;
typedef struct{
int type_transaction;
char desc_transaction[80];
float amount_of_money;
Date_of_transaction date;
}Trecord;
typedef struct{
Trecord r;
}Tarray;
int count(int *count);
void add_new_record(Trecord records,Tarray t[],int *counter,int *count);
void read_data_from_disc(Trecord *records);
void save_curiculum_to_disc(Tarray records[]);
void add_money(Trecord *records);
void spend_money(Trecord *records);
void print_a_report(Tarray *records,int *counter);
void delete_a_record(Trecord *record);
void initialize(Trecord records);
void initializeRecord(Tarray records[]);
int main(int argc, char** argv) {
int quit = 0;
int choice = 0;
static int counter = 0;
int count = -1;
Trecord records;
Tarray recordData[SIZE];
initializeRecord(recordData);
while(!quit) {
printf("\nChoose an option:\n"
"1. Add New Record\n"
"2. Read Data from File\n"
"3. Save Data to File\n"
"4. Print Report\n"
"5. Quit\n" );
scanf("%d", &choice);
switch(choice){
case 1:
count++;
add_new_record(records,recordData,&counter,&count);
printf("%d",count);
break;
case 2:
read_data_from_disc(&records);
break;
case 3:
save_curiculum_to_disc(recordData);
break;
case 4:
count++;
print_a_report(recordData,&count);
break;
case 5:
quit = 1;
break;
default:
printf("Invalid Selection\n");
}
}
return (EXIT_SUCCESS);
}
void initializeRecord(Tarray records[]){
int i;
for(i=0;i
modified 26-Nov-11 12:57pm.
|
|
|
|
|
Please wrap your code using <pre> and </pre> tags... this is painful to look at.
|
|
|
|
|
idbee2k3 wrote: ...is working but I am having problem...
That appears to be contradictory. It's either working or it isn't.
idbee2k3 wrote: Did any one know what is wrong.
Hard to tell since you've not shown any code that reads or writes. The only thing you've shown is menu code which is completely irrelevant to the problem.
Use the debugger to narrow the problem down to just a handful of lines, then come back and post those.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
First off, I'm not sure if I'm quite in the right forum or not, so just let me know if I should post elsehwere. With that said...
I'm brand new to C++ and am trying to wrap my brain around something. I know that I can use a MAIN function in a .CPP file and use it to grab command line arguments. I'm trying to add this feature to an existing clump of code we've got at work (I'm trying to expand my skills, and it's a small utility we techies use only occasionally). Anyway, I can't figure out how to use a MAIN function if there isn't already one (I can make it work in a brand new test project just fine). My current attempt to tweak the code sort of looks like this:
#include "stdafx.h"
#include ...a few other files.....
class CApp : public CWinAppEx
{
public:
CApp();
public:
virtual BOOL InitInstance();
};
extern CApp theApp;
int main(int argc, char *argv[])
{
MessageBox(NULL, L"This should display first, but doesn't currently show up at all.", NULL, NULL);
}
CApp::CApp()
{
MessageBox(NULL, L"This should display second, but currently shows up first.", NULL, NULL);
}
CApp theApp;
BOOL CApp::InitInstance()
{
MessageBox(NULL, L"This should display third, but currently shows up second.", NULL, NULL);
...does other stuff here...
}
So what do I need to do to use MAIN correctly to grab the command line arguments?
Thanks!
|
|
|
|
|
|
You have code for a Windows application there. And it also looks like it is using MFC. You won't find a main(), nor will you need to. Odd, though is that you have 'theApp' declared twice. That's definitely not a good start.
There are methods of the CWinAppEx class that can be called in InitInstance to assist with command line handling.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
As others have said, you either have main() or you have your WinApp (theApp ) but not both. And definitely not two instantiations of theApp .
The command line arguments can be accessed during your InitInstance() function by looking at the m_lpCmdLine data member of your class.
There are a number of classes / functions that can help you parse it in the argc/argv style you're accustomed to, links are in earlier answers to this question.
|
|
|
|
|
|
in your CWinApp:InitInstance, you should be able to access the __argv and __argc variables.
|
|
|
|
|
I did not know that, been tokenizing m_lpCmdLine myself. +5 for the info.
|
|
|
|
|
Hi ,
How can we represent structure bitfiled in the UML Model??
|
|
|
|
|
|
If i have the following case,
Struct Mode
{
union
{
unsigned char MSB;
struct
{
unsigned char a:2
unsigned char b:3
unsigned char c:3
}
}
}
How to model the struct "Mode" in the class diagram?
|
|
|
|
|
[ Here ] is a good UML primer.
#include <iostream>
using namespace std;
class c_Mode
{
public:
union
{
unsigned char MSB;
struct
{
unsigned char a:2;
unsigned char b:3;
unsigned char c:3;
};
};
} ;
struct s_Mode
{
public:
union
{
unsigned char MSB;
struct
{
unsigned char a:2;
unsigned char b:3;
unsigned char c:3;
};
};
} ;
int main()
{
c_Mode clsMode;
clsMode.a=0;
clsMode.MSB=0;
s_Mode mode ;
mode.a=0;
mode.MSB=0;
return 0;
}
|
|
|
|
|
|
|
People Hi!People, prompt why VC ++ doesn't open title files, can where it is necessary to adjust?
It is all to be in one folder, and doesn't want to open.
|
|
|
|
|
Your question is not very clear, but if you are having trouble accessing files in your project then check that the location property is correct.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Ok! in my project there is two file-first main.cpp and main.h,and i am using command #nclude"main.h",But in the с++ editor the error that can't open this file Both files are in one directory
|
|
|
|
|
What do you mean "can't open"? If both files are in the correct directory then the editor will find them. You must have some other problem that is preventing it from locating the file. I presume the word "#nclude " above is a simple typo here only and not in your source file.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
PeLeg89 wrote: #nclude
Try #include
==============================
Nothing to say.
|
|
|
|
|
If your editor can't find a file, it means either:
0. File doesn't exist.
1. Path is not specified correctly in the include (if using entire path).
2. Path is not part of the project library/include directories (if using <> ).
3. I believe I've also seen this occur if the file is not part of the project (although don't quote me on that one, don't quite remember)
|
|
|
|
|
Thank all,you helped me ,I think this is 3 item
|
|
|
|
|
Great
|
|
|
|
|
Can someone assist me how to read/write physical memory location from IP address?
Thanks.
|
|
|
|