|
I am currently working on fixing a project for a client. A little information about the project first:
1. Originally developed in Visual Studio 2012 using xp_v110 build tools
2. Multiple projects in the solution
3. Currently updating/debugging in Visual Studio 2017 using VS 2015/xp_v140 build tools
4. Working on Windows 10
The application will run in debug mode, however if I just leave the application after starting the debug session (i.e. not opening/clicking on the application to open it as it starts minimized in the tray), the application crashes after 1-2 minutes.
Unfortunately the IDE is showing that the crash is taking place in chkstk.asm with the following message:
Exception thrown at 0x0064EDF9 in <<exe name="">>: 0xC00000FD: Stack overflow (parameters 0x00000000, 0x000A2000).
I have updated the exception settings to break when all C++ Exceptions are thrown, checked the box that says "Break when this exception type is thrown", and wrapped the initial method that runs in a try block, however I can never catch the error in the C++ code; it always occurs in the chkstk.asm file.
Any suggestions on how I can find out where in the C++ code the exception is occurring. Like I said, this is an update for a client and the original programmer is not available, and they never commented their code, so it is difficult enough trying to go through all this. Any help/suggestions would be greatly appreciated. Thanks in advance.
A black hole is where God tried to divide by zero.
There are 10 kinds of people in the world; those who understand binary and those who don't.
|
|
|
|
|
You need to get the stack trace at the time of the crash and walk back through it to find out who is using all the stack space.
|
|
|
|
|
You should make small memory dump using windows task manager. If you have application .pdb files and source files you can load windows dump file with Visual studio and debug it as managed code. If there are symbols debugging files (pdb) you can see thread`s stack in appropriate state.
|
|
|
|
|
I think this message was meant for the OP.
|
|
|
|
|
I suggest you launch the app in the debugger and then wait for ~20 seconds then break into the debugger. Most likely you'll see the a deep stack as it's in the midst of eating up stack space. That callstack should lead you to the issue.
|
|
|
|
|
please tell me what is going on in below code
if(curl)
{
curl_easy_setopt(curl,CURLOPT_URL,url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,&ret);
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,WriteFunction);
CURLcode res = curl_easy_perform(curl);
if(res != CURLE_OK)
{
curl_easy_cleanup(curl);
return 0;
}
curl_easy_cleanup(curl);
if(ret.find("Ok"))
{
char* r=new char[ret.length()+1];
strcpy(r,ret.c_str());
char* p=strtok(r,"|");
p=strtok(NULL,"|");
return atoi(p);
}
}
return 1;
}
|
|
|
|
|
It appears to use some third party library (curl ?) to obtain text input, find the first token and convert its text to an integer, which it then returns to the caller. I would suggest getting the documentation for the library and studying that.
|
|
|
|
|
|
i have a code for sms send my api provider is changed below mention is my code problem is what will return my new api vender so i can use that dll in my vfp application.
code
#include "stdafx.h"
#include "smsservice.h"
#include <string>
using namespace std;
size_t WriteFunction( char *ptr, size_t size, size_t nmemb, void *userdata)
{
string* s=(string*)userdata;
int i;
for(i=0;i<size*nmemb;i++)
{
s->push_back(ptr[i]);
}
return i;
}
int _declspec(dllexport) SendSms(LPCSTR userId,LPCSTR userPass,LPCSTR phoneNumber,LPCSTR smsText,LPCSTR senderId)
{
CURL* curl;
curl=curl_easy_init();
string ret;
string url="http://way2send.in/submitsms.jsp?Userid=";
char* esc=curl_easy_escape(curl,userId,strlen(userId));
url+=esc;
curl_free(esc);
url+="&UserPassword=";
esc=curl_easy_escape(curl,userPass,strlen(userPass));
url+=esc;
curl_free(esc);
url+="&PhoneNumber=";
esc=curl_easy_escape(curl,phoneNumber,strlen(phoneNumber));
url+=esc;
curl_free(esc);
url+="&Text=";
esc=curl_easy_escape(curl,smsText,strlen(smsText));
url+=esc;
curl_free(esc);
url+="&GSM=";
esc=curl_easy_escape(curl,senderId,strlen(senderId));
url+=esc;
curl_free(esc);
if(curl)
{
curl_easy_setopt(curl,CURLOPT_URL,url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl,CURLOPT_WRITEDATA,&ret);
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,WriteFunction);
CURLcode res = curl_easy_perform(curl);
if(res != CURLE_OK)
{
curl_easy_cleanup(curl);
return 0;
}
curl_easy_cleanup(curl);
if(ret.find("Ok"))
{
char* r=new char[ret.length()+1];
strcpy(r,ret.c_str());
char* p=strtok(r,"|");
p=strtok(NULL,"|");
return atoi(p);
}
}
return 1;
}
|
|
|
|
|
What is the question? And why have you posted this in the Managed C++/CLI section?
|
|
|
|
|
Your code looks like the native C++. So why did you post in the managed C++/CLI forum?
|
|
|
|
|
Your code looks like the native C++.
|
|
|
|
|
need some help with my code, I tried in many ways to make simple filtering image with array 3x3, but cant make it. any ideas how shall I start it?
<pre>#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;
typedef struct tagBITMAPFILEHEADER {
unsigned short bfType;
unsigned int bfSize;
short bfReserved1;
short bfReserved2;
unsigned int bfOffBits;
} BITMAPFILEHEADER;
typedef struct tagBITMAPINFOHEADER {
unsigned int biSize;
int biWidth;
int biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
int biXpelsPerMeter;
int biYpelsPerMeter;
unsigned int biClrUses;
unsigned int biClrImportant;
} BITMAPINFOHEADER;
int odczytajBFH(ifstream &ifs, BITMAPFILEHEADER &bfh);
int odczytajBIH(ifstream &ifs, BITMAPINFOHEADER &bih, int kursor);
void zapiszBFH(ofstream &ofs, BITMAPFILEHEADER &bfh);
void zapiszBIH(ofstream &ofs, BITMAPINFOHEADER &bih);
unsigned char* odczytajDaneObrazu(ifstream &ifs, unsigned int rozmiar, int kursor);
void odczytajRGB(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
unsigned char * polaczRGB(int **niebieski, int **zielony, int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc);
void zwolnij_pamiec(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, int wysokosc);
void zapiszDaneObrazu(ofstream &ofs, unsigned char *obraz, unsigned int rozmiar);
int main()
{
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
string str = "bitmap.bmp";
const char * nazwa_pliku = str.c_str();
ifstream ifs(nazwa_pliku, ios::binary) ;
if( !ifs.is_open() )
{
cout << "\nBlad otwarcia pliku";
return 0;
}
ofstream ofs("out.bmp", ios::binary);
int kursor = odczytajBFH(ifs, bfh);
kursor = odczytajBIH(ifs, bih, kursor);
zapiszBFH(ofs, bfh);
zapiszBIH(ofs, bih);
unsigned int rozmiar = bfh.bfSize - bfh.bfOffBits;
int szerokosc = bih.biWidth;
int wysokosc = bih.biHeight;
unsigned char* obraz = odczytajDaneObrazu(ifs, rozmiar, kursor);
int **niebieski = new int*[wysokosc];
int **zielony = new int*[wysokosc];
int **czerwony = new int*[wysokosc];
for (int i = 0; i < wysokosc; i++ )
{
niebieski[i] = new int [szerokosc];
zielony[i] = new int [szerokosc];
czerwony[i] = new int [szerokosc];
}
odczytajRGB(obraz, niebieski, zielony, czerwony, rozmiar, szerokosc, wysokosc );
cout << "bfh.bfType: "<<bfh.bfType <<endl;
cout << "bfh.bfSize: "<< bfh.bfSize <<endl;
cout << "bfh.bfReserved1 "<<bfh.bfReserved1 <<endl;
cout << "bfh.bfReserved1 "<<bfh.bfReserved2 <<endl;
cout << "bfh.bfOffBits: "<<bfh.bfOffBits <<endl;
cout<<endl;
cout << "bih.biSize: "<<bih.biSize <<endl;
cout << "bih.biWidth: "<<bih.biWidth <<endl;
cout << "bih.biHeight: "<<bih.biHeight <<endl;
cout << "bih.biPlanes: " <<bih.biPlanes <<endl;
cout << "bih.biBitCount: " <<bih.biBitCount <<endl;
cout << "bih.biCompression: "<<bih.biCompression <<endl;
cout << "bih.biSizeImage: "<< bih.biSizeImage <<endl;
unsigned char * obraz2 = polaczRGB(niebieski, zielony, czerwony, rozmiar, szerokosc, wysokosc);
zapiszDaneObrazu(ofs, obraz2, rozmiar);
zwolnij_pamiec(obraz, niebieski, zielony, czerwony, wysokosc );
ifs.close();
system("pause");
return 0;
}
int odczytajBFH(ifstream &ifs, BITMAPFILEHEADER &bfh)
{
ifs.read(reinterpret_cast<char *>(& bfh.bfType), 2);
ifs.read(reinterpret_cast<char *>(& bfh.bfSize), 4);
ifs.read(reinterpret_cast<char *>(& bfh.bfReserved1), 2);
ifs.read(reinterpret_cast<char *>(& bfh.bfReserved2), 2);
ifs.read(reinterpret_cast<char *>(& bfh.bfOffBits), 4);
return ifs.tellg();
}
void zapiszBFH(ofstream &ofs, BITMAPFILEHEADER &bfh)
{
ofs.write(reinterpret_cast<char *>(& bfh.bfType), 2);
ofs.write(reinterpret_cast<char *>(& bfh.bfSize), 4);
ofs.write(reinterpret_cast<char *>(& bfh.bfReserved1), 2);
ofs.write(reinterpret_cast<char *>(& bfh.bfReserved2), 2);
ofs.write(reinterpret_cast<char *>(& bfh.bfOffBits), 4);
}
int odczytajBIH(ifstream &ifs, BITMAPINFOHEADER &bih, int kursor)
{
ifs.seekg(kursor, ios::beg);
ifs.read(reinterpret_cast<char *>(& bih.biSize), 4);
ifs.read(reinterpret_cast<char *>(& bih.biWidth), 4);
ifs.read(reinterpret_cast<char *>(& bih.biHeight), 4);
ifs.read(reinterpret_cast<char *>(& bih.biPlanes), 2);
ifs.read(reinterpret_cast<char *>(& bih.biBitCount), 2);
ifs.read(reinterpret_cast<char *>(& bih.biCompression), 4);
ifs.read(reinterpret_cast<char *>(& bih.biSizeImage), 4);
ifs.read(reinterpret_cast<char *>(& bih.biXpelsPerMeter), 4);
ifs.read(reinterpret_cast<char *>(& bih.biYpelsPerMeter), 4);
ifs.read(reinterpret_cast<char *>(& bih.biClrUses), 4);
ifs.read(reinterpret_cast<char *>(& bih.biClrImportant), 4);
kursor = ifs.tellg();
return kursor;
}
void zapiszBIH(ofstream &ofs, BITMAPINFOHEADER &bih)
{
ofs.write(reinterpret_cast<char *>(& bih.biSize), 4);
ofs.write(reinterpret_cast<char *>(& bih.biWidth), 4);
ofs.write(reinterpret_cast<char *>(& bih.biHeight), 4);
ofs.write(reinterpret_cast<char *>(& bih.biPlanes), 2);
ofs.write(reinterpret_cast<char *>(& bih.biBitCount), 2);
ofs.write(reinterpret_cast<char *>(& bih.biCompression), 4);
ofs.write(reinterpret_cast<char *>(& bih.biSizeImage), 4);
ofs.write(reinterpret_cast<char *>(& bih.biXpelsPerMeter), 4);
ofs.write(reinterpret_cast<char *>(& bih.biYpelsPerMeter), 4);
ofs.write(reinterpret_cast<char *>(& bih.biClrUses), 4);
ofs.write(reinterpret_cast<char *>(& bih.biClrImportant), 4);
}
unsigned char* odczytajDaneObrazu(ifstream &ifs, unsigned int rozmiar, int kursor)
{
ifs.seekg(kursor, ios::beg);
unsigned char *obraz = new unsigned char[rozmiar];
ifs.read(reinterpret_cast<char*>(obraz), rozmiar);
return obraz;
}
void zapiszDaneObrazu(ofstream &ofs, unsigned char *obraz, unsigned int rozmiar)
{
ofs.write(reinterpret_cast<char*>(obraz), rozmiar);
}
void odczytajRGB(unsigned char *obraz, int **niebieski, int **zielony,
int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc)
{
int zerowe_bajty = rozmiar/wysokosc - 3*szerokosc;
int k = 0;
for (int i = 0; i < wysokosc; i++)
{for (int j = 0; j < szerokosc; j++)
{
niebieski[i][j]=obraz[k++];
zielony[i][j]=obraz[k++];
czerwony[i][j]=obraz[k++];
}
k+=zerowe_bajty;
}
}
unsigned char *polaczRGB(int **niebieski, int **zielony, int **czerwony, unsigned int rozmiar, int szerokosc, int wysokosc)
{
int zerowe_bajty = rozmiar/wysokosc - 3*szerokosc;
unsigned char * obraz = new unsigned char [rozmiar];
for (int k = 0; k < rozmiar; k++)
obraz[k] = 0;
int k = 0;
for (int i = 0; i < wysokosc; i++)
{for (int j = 0; j < szerokosc; j++)
{
obraz[k++]=niebieski[i][j];
obraz[k++]=zielony[i][j];
obraz[k++] = czerwony[i][j];
}
k+=zerowe_bajty;
}
return obraz;
}
void zwolnij_pamiec(unsigned char *obraz, int **niebieski, int **zielony , int **czerwony, int wysokosc)
{
for(int i = 0; i < wysokosc; i++)
{
delete [] niebieski[i];
niebieski[i] = NULL;
delete [] zielony[i];
zielony[i] = NULL;
delete [] czerwony[i];
czerwony[i] = NULL;
}
delete [] niebieski;
niebieski = NULL;
delete [] zielony;
zielony = NULL;
delete [] czerwony;
czerwony = NULL;
delete [] obraz;
obraz = NULL;
}
|
|
|
|
|
I don't know Polish so that it is really hard to retrace the code.
But you missed some points:- There are two versions of info headers with different sizes which can be identified using the
biSize member: BITMAPINFOHEADER and BITMAPV5HEADER
- When
biCompression is BI_BITFIELDS , these bitfields are stored after the info header.
- Your code supports only 24-bit RGB bitmaps. So you should check if the file is in that format (
biBitCount == 24).
You can read the pixel data from file offset bfOffBits with size biSizeImage which includes the padding bytes. But your code starts reading after the info header which is the location of the bitfields table or still within a BITMAPV5HEADER .
|
|
|
|
|
Dear friends,
I don't understand the below codes, please explain for me:
case 3:
{
system("cls");
do
{
found = 0;
printf("\n\n\t..Contact Search\n\t=================================\n\t...Name of Contact to search: ");
fflush(stdin);
scanf("%[^\n]",&querry);
l=strlen(querry);
fp=fopen("Contact.dll","r");
system("cls");
printf("\n\n::Search result for: 's'\n====================================\n", querry);
while(fread(&list,sizeof(list),1,fp)==1)
{
for(i=0;i<=l;i++)
{
name[i]=list.name[i];
name[1]='\0';
}
}
if (stricmp(name,querry)==0)
{
printf("\n..::Name\t: %s\n..::Phone\t: %ld\n....::Address\t %s\n.....::Email\t:%s\n", list.name,list.ph,list.add,list.email);
found++;
if(found%4==0)
{
printf("Press any key to continue..");
getch();
}
}
if(found==0)
{
printf("\n..:No match found");
}
else
{
printf("\n....match(s) found!",found);
}https:
fclose(fp);
printf("\n.......Try again ? \n\n\t[1] Yes\t\t[0] No\n\t");
scanf("%d",&ch);
}
while (ch==1);
}
break;
----------------------------------------------
while(fread....) --> what does this mean ?
if (stricmp(name,q .... --> what does it mean ?
Please explain for me , thank you very much!
Hieu
|
|
|
|
|
Hiếu Ngô wrote: while(fread....) --> what does this mean ? It means repeat the loop while that condition remains true. So if the fread function returns any value other than 1 the loop will terminate.
Hiếu Ngô wrote: if (stricmp(name,q. --> what does it mean ? It means compare two strings ignoring the case of characters. So "AbCd" will match "aBcD" or "abcd" etc.
Full details of these, and other functions, constructs etc., are in the language references on MSDN.
|
|
|
|
|
|
Hey all,
Here's some great news for everyone still doing C++/CLI coding! ReSharper C++ has added C++/CLI support. I'm eager to try this out!
Blog Post:
C++/CLI support comes to ReSharper C++[^]
John
|
|
|
|
|
in the code below i would like to know how the logic of finding the angle at a turn works.
int main()
{
RenderWindow app(VideoMode(640, 480), "Car Racing Game!");
app.setFramerateLimit(60);
Texture t1, t2;
t1.loadFromFile("images/background.png");
t2.loadFromFile("images/car.png");
Sprite sBackground(t1), sCar(t2);
sCar.setPosition(300, 300);
sCar.setOrigin(22, 22);
float x = 300, y = 300;
float speed = 0, angle = 0;
float maxSpeed = 12.0;
float acc = 0.2, dec = 0.3;
float turnSpeed = 0.08;
while (app.isOpen())
{
Event event;
while (app.pollEvent(event))
{
if (event.type == Event::Closed)
app.close();
if (Keyboard::isKeyPressed(Keyboard::Escape))
app.close();
}
bool Up = false, Right = false, Down = false, Left = false;
if (Keyboard::isKeyPressed(Keyboard::Up)) Up = true;
if (Keyboard::isKeyPressed(Keyboard::Right)) Right = true;
if (Keyboard::isKeyPressed(Keyboard::Down)) Down = true;
if (Keyboard::isKeyPressed(Keyboard::Left)) Left = true;
if (Up && speed < maxSpeed)
if (speed < 0) speed += dec;
else speed += acc;
if (Down && speed > -maxSpeed)
if (speed > 0) speed -= dec;
else speed -= acc;
if (!Up && !Down)
if (speed - dec > 0) speed -= dec;
else if (speed + dec < 0) speed += dec;
else speed = 0;
if (Right && speed != 0) angle += turnSpeed * speed / maxSpeed;
if (Left && speed != 0) angle -= turnSpeed * speed / maxSpeed;
x += sin(angle) * speed ;
y -= cos(angle) * speed ;
app.clear(Color::White);
app.draw(sBackground);
sCar.setPosition(x, y);
sCar.setRotation(angle * 180 / 3.141592) ;
sCar.setColor(Color::Red);
app.draw(sCar);
app.display();
}
return 0;
}
How the below logic works ?
Quote: if (Right && speed != 0) angle += turnSpeed * speed / maxSpeed;
if (Left && speed != 0) angle -= turnSpeed * speed / maxSpeed;
x += sin(angle) * speed ;
y -= cos(angle) * speed ;
Thank you
|
|
|
|
|
Consider the two chunks of code separately.
The first two lines are updating angle by a fraction of turnSpeed. If speed were == maxSpeed then speed/maxSpeed = 1. So angle += turnSpeed for a right-turn. turnSpeed = 0.08 so that's in Radians which is 4.58 degrees. This means if you're turning right or left at max speed, it'll add or remove 4.58 degrees each time through. If speed is less than the max, then the angle will change by a smaller amount (a fraction of .08 radians). Try it in the debugger and see the change.
The last two lines are updating the x,y location of the car using it's orientation (angle). cos(angle) is typically the x portion of an angle so I'm not sure why it modifies the y coor with that but that's what it does. sin(angle) or cos(angle) produces a value from 0-1 (which it uses as a percentage) * speed. That means x or y changes by a fraction of speed in the direction of angle.
It would probably help you to print out the values or use the debugger.
Hope this helps,
John
|
|
|
|
|
|
In native code, we often use helper classes to save a reference to a member, set its value and reset it in destruction. standard stuff.
Unfortunately, I haven't found a good way in a ref class to do the same and I'm hoping for some tips here.
Since I cannot hold a reference to a member of a managed object as a member of another object, I tried using a tracking reference. Unfortunately, that results in an similar error:
error C3160: 'System::Boolean ^%': a data member of a managed class cannot have this type
note: an interior reference can never be allocated on the gc heap
An example I hope to get working...
ref class Foo { bool m_guard; . . . }
ref class PushBool sealed {
bool ^% m_tref;
public:
PushBool(bool ^% b, bool newVal) : m_tref(b), m_oldval(b) { b = newVal; }
~PushBool() { m_tref = m_oldval; }
};
usage...
void Foo::work() {
if (m_guard) return;
PushBool no_reentry(m_guard, true);
...
}
Do any of the C++/CLI devs here have advice on handling this? I can probably concoct a way to make it work but was hoping for a reusable utility class.
John
|
|
|
|
|
Hello guys
I've have a c++ source code for a litle phoonbook.
It has the insert option, View and delete but i've can't edit a record!
Here is source code please add a edit part for this code as possible.
Also it does not going back to main menu after adding a record.
thanks
<pre>#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#define NAMES 50
#define EMAIL 20
#define PHONE 20
#define ADDRESS 8
#define MOBILE 10
#define SIZE 500
void welcome_note();
void record();
void view();
void search();
void del_rec();
char info[SIZE];
struct addressbk
{
char name [NAMES] ;
char sname [NAMES] ;
char emailadd [EMAIL] ;
char address [ADDRESS];
char mobile [MOBILE];
char phone [PHONE];
char codemelli [PHONE];
} addressbk;
FILE *Records;
FILE *rectemp;
void main()
{
int choice=0;
system("cls");
system("color 17");
fflush(stdin);
welcome_note();
printf("\nEnter your Choice here \t");
scanf("%i",&choice);
fflush(stdin);
switch (choice)
{
case 1:
{
system("cls");
view();
break;
}
case 2:
{
system("cls");
record();
break;
}
case 3:
{ system("cls");
search();
break;
}
case 4:
{ system("cls");
del_rec();
break;
}
case 5:
{
system("cls");
break;
}
default:
{
printf("Please Only Choose Between NO. 1-5\n"); system("pause");
system("cls");
main();
}
}
}
void record()
{
char choice2;
do
{ Records = fopen("Records.txt","a+");
printf("Enter Name\n");
fflush(stdin);
scanf("%s",addressbk.name);
printf("Enter Second Name\n");
fflush(stdin);
scanf("%s",addressbk.sname);
printf("Enter E-mail address\n");
fflush(stdin);
scanf("%s",addressbk.emailadd);
printf("Enter address\n");
fflush(stdin);
scanf("%s",addressbk.address);
printf("Enter mobile\n");
fflush(stdin);
scanf("%s",addressbk.mobile);
printf("Enter Code Melli no\n");
fflush(stdin);
scanf("%s",addressbk.codemelli);
printf("Enter Phone Number no\n");
fflush(stdin);
scanf("%s",addressbk.phone);
fprintf(Records,"%s %s %s %s %s %s %s \n",addressbk.name,addressbk.sname,addressbk.emailadd,addressbk.address,addressbk.mobile,addressbk.codemelli,addressbk.phone);
fflush(stdin);
fclose(Records);
printf("WOULD LIKE TO CONTINUE? Y/N \n");
scanf("%c",&choice2);
fflush(stdin);
if (choice2=='n'||choice2=='N')
{
system("cls");
main();
}
}while(choice2=='y'||choice2=='Y');
}
void view()
{
char choice3;
Records = fopen("Records.txt","a+");
do
{
fgets(info,SIZE,Records);
printf("%s\n",info);
}while(!feof(Records));
fclose(Records);
system("pause");
printf("Search for records??(Y/N)\n");
scanf("%c",&choice3);
fflush(stdin);
if (toupper(choice3)=='Y')
{
search();
}
else if(toupper(choice3)=='N')
{
fclose(Records);
system("pause");
system("cls");
main();
}
else
{
fclose(Records);
system("cls");
}
}
void welcome_note()
{
printf("\t\t Phone BOOK V:1 \n\n\n");
printf("\t\t ProGrammeR: Fatemeh \n\n\n");
printf("\t\t ----------------------------------------\n");
printf("\t\t - CHOOSE ONE BETWEEN (1-5) -\n");
printf("\t\t ----------------------------------------\n");
printf("\t\t - 1 : VIEW RECORDS -\n\n");
printf("\t\t - 2 : MAKE NEW ENTRIES -\n\n");
printf("\t\t - 3 : SEARCH RECORDS -\n\n");
printf("\t\t - 4 : DELETE RECORDS -\n\n");
printf("\t\t - 5 : EXIT -\n\n");
printf("\t\t ----------------------------------------\n");
}
void search()
{
char Target[SIZE];
int Found=0;
if((Records=fopen("Records.txt","r"))==NULL)
printf("Recordi Peyda Nashod!!!\n\n");
else
{
system("cls");
printf("\n\n");
printf("\t----------------- SEARCH --------------");
printf("\n\n");
printf("\tEnter Code Melli to search:");
fflush(stdin);
scanf("%s",Target);
while(!feof(Records)&& Found==0)
{
fscanf(Records,"%s %s %s %s %s %s %s",addressbk.name,addressbk.sname,addressbk.emailadd,addressbk.address,addressbk.mobile,addressbk.codemelli,addressbk.phone);
if(strcmp(Target,addressbk.codemelli)==0)
Found=1;
}
if(Found)
{
printf(".......Record Peyda Shod\n");
system("pause");
system("cls");
printf("1 FILE FOUND : \n\n\n");
printf("First Name: %s\n",addressbk.name);
printf("Last Name: %s\n",addressbk.sname);
printf("E-mail: %s\n",addressbk.emailadd);
printf("Address : %s\n",addressbk.address);
printf("mobile: %s\n",addressbk.mobile);
printf("Code Melli: %s\n",addressbk.codemelli);
printf("Phone Number: %s\n",addressbk.phone);
system("pause");
main();
}
else if(!Found)
{
printf("Motasfim Recordi Peyda Nashod\n");
system("pause");
main();
}
fclose(Records);
}
}
void del_rec()
{
char Target[SIZE];
int Found=0;
system("cls");
rectemp=fopen("rectemp.txt","w");
if((Records=fopen("Records.txt","r"))==NULL)
printf("RECORDI YAFT NASHOD!!!\n\n");
else{
printf("\n\n");
printf("\t--------------- DELETE ----------------");
printf("\n\n");
printf("\tEnter Code Melli to Delete: ");
fflush(stdin);
gets(Target);
while(!feof(Records))
{
fscanf(Records,"%s %s %s %s %s %s %s ",addressbk.name,addressbk.sname,addressbk.emailadd,addressbk.address,addressbk.mobile,addressbk.codemelli,addressbk.phone);
if(feof(Records))
break;
if(strcmp(Target,addressbk.codemelli)!=0)
fprintf(rectemp,"%s %s %s %s %s %s %s \n",addressbk.name,addressbk.sname,addressbk.emailadd,addressbk.address,addressbk.mobile,addressbk.codemelli,addressbk.phone);
else {
Found=1;
printf(".......Record Peyda Shod \n");
system("pause");
printf("First Name:%s\n",addressbk.name);
printf("Last Name:%s\n",addressbk.sname);
printf("E-mail:%s\n",addressbk.emailadd);
printf("Address : %s\n",addressbk.address);
printf("mobile: %s\n",addressbk.mobile);
printf("Code Melli: %s\n",addressbk.codemelli);
printf("Phone Number: %s\n",addressbk.phone);
fflush(stdin);
system("pause");
}
}
if (!Found)
{
printf("\tRECORD NOT FOUND\n"); }
printf("\tRECORD DELETED!!\n");
fclose(Records);
fclose(rectemp);
remove("Records.txt");
rename("rectemp.txt","Records.txt");
main(); }
}
|
|
|
|
|
Sorry, this site does not provide code to order. Please edit your question and explain what does not work, and where in the code the problem lies. It would also help if you removed all the code that is not related to the problem.
|
|
|
|
|
I'm not going to write the complete edit function for you. But you already have most of the parts because editing can be implemented by selecting, reading, entering new data, deleting the old record, and inserting the edited data.
Quote: Also it does not going back to main menu after adding a record. Never call main() from within your code as done here in the record() function:
if (choice2=='n'||choice2=='N')
{
system("cls");
main();
} Just return from the function (simply delete the above code block). Then execution continues after the function call in main() . Similar for the other functions where you call main() too.
To process the next operation you have to implement a loop in main() that gets and processes the next choice until the exit option is selected:
do
{
printf("\nEnter your Choice here \t");
scanf("%i",&choice);
fflush(stdin);
switch (choice)
{
}
system("cls");
} while (choice != 5);
Note also that this the wrong forum because this is about Managed C++/CLI as stated in the topmost (sticky) post. Please use the C / C++ / MFC Discussion Boards[^] or Ask a Question for further C/C++ related questions where the latter is the better choice when posting larger amounts of code (which should be avoided).
|
|
|
|
|