C++ :: Properly Exiting A Program

Sep 2, 2013

If I were to exit a program, is it okay if I fail to properly destroy whatever structures were allocated?

For instance, if I do this with SDL, there might be obvious consequences like a dead window perhaps. But if I do this with a POD structure, is it okay?

Also, I realize RAII is supposed to fix parts of this but it's not perfect when environments are suddenly cut off with something like exit(1/0);

View 2 Replies


ADVERTISEMENT

C++ :: How To Repeat For Next Word Not Exiting The Program

Sep 16, 2013

everything works it just how am i repeat for the next word not exiting the program.

// Word Jumble
// The classic word jumble game where the player can ask for a hint

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
enum fields {WORD, HINT, NUM_FIELDS};

[Code]...

View 1 Replies View Related

C :: Code Keeps Exiting With 0 When Run On Visual Studio

Mar 26, 2013

Whenever i run this on Visual Studio, it keeps exiting with code 0

Code:
#include "stdafx.h"
#include "stdio.h" // NULL defined here
#include "stdlib.h" // malloc function here
#include <string.h> //for handling strings
#include <ctype.h>

char reg_num[21]; //used in get_new_value

[Code] .....

View 5 Replies View Related

C :: Program Doesn't Properly Compute Simple Polynomial

Feb 7, 2014

The program will ask for the user to enter a value for x, then compute the following polynomial: 3x^5 + 2x^4 - 5x^3 - x^2 + 7x - 6.However, when I double check it with my calculator I get a wrong answer for random values of x. To simplify my problem I'm using only integers.

Code:

#include <stdio.h>
int main(void)
{
int x, polynomial;
}

[code]...

View 5 Replies View Related

Visual C++ :: Exiting Application During While Loop Operation

Jun 16, 2013

I have a VC++ 6 dialog-based application. This application is intended for reading data from a USB device (this is a FTDI FT245R chip). I have a start button on the dialog. On clicking it, unsigned char data retrieved from the USB device is displayed on the dialog. The start button invokes a function which includes a while (1) loop inside which the USB device is read and the values displayed.

There are no break or continue statements inside the always operating while (1) loop. All this works fine. My problem is how do I exit the application as normally it would just run forever? I have put an exit button on the dialog with code added to call OnOK(). Normally this would nicely close the application but as I have an endless while loop in my application so this button doesn't seem to work. Nothing happens on clicking it and clicking it repeatedly just hangs the program.

View 8 Replies View Related

C :: Ubuntu Build - Test Program To See If Shared Library Properly Built

May 22, 2013

I have created a shared object in Ubuntu (libMYLIB.so). I am now trying to compile a simple test program (testmylib.c) to see if the shared object is properly built. I am getting an error that the build cannot find the shared object. My build command is:

gcc -lm -l /dir/mylib -lMYLIB.so -o testmylib testmylib.c

where /dir/mylib is where my source and libMYLIB.so reside.

What am I doing wrong?

View 9 Replies View Related

C++ :: Count Function In Program Not Working Properly - Counting Blank Nodes

May 9, 2013

I tested my count funtion. So my count function is not working properly, it should return 5 because 5 words have prefix "tal," but it is giving me 10. It's counting blank nodes.

This is my main.cpp file

int main() {
string word;
cout<<"Enter a word"<<endl;
cin >> word;
string filename;

[Code] .....

View 9 Replies View Related

C++ :: Sort Players In Descending Order On The Basis Of Score - Program Not Working Properly

Feb 11, 2015

#include <iostream.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

class Player {
private:
char name[20];
int score;

[Code] .....

View 5 Replies View Related

C :: Cannot Get Strstr To Work Properly

Aug 26, 2014

I am unable to get the string seaching function to work. it always says "Nothing found" I am stumped.

Code:

#include <stdio.h>
#include <string.h>
char tracks[][80] = {
"I left my Heart at Harvard Medical School",
"Newark, Newark, You suck balls",
"Dancing with a dork",
"From Here to maternity",
"The Girl from Iwo Jima",

[Code]....

View 3 Replies View Related

C :: String Not Validating Properly?

Mar 5, 2013

1. In main() in the while loop entering 'q' does not exit.

2. in the isbnValidation function. The size check for minimum length words will work, but the check for "Invalid ISBN character" doesn't.

3. Every ISBN entered returns as valid. The formula is supposed to multiply the first digit by 10, next by 9 etc (skipping all the dashes) and add up to a weighted total which if valid will divide evenly by 11.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ISBNMIN 10
#define ISBNMAX 14

[Code].....

View 4 Replies View Related

C++ :: File Is Not Reading Properly?

Mar 30, 2013

I have a file which I am unable to read properly. This is binary file so my code is"

#include<iostream>
#include<fstream>
#include<string>

[Code]....

the file to read can be download from this link :

[URL]

The first content of file should be 1 I am missing few content from the begining

View 2 Replies View Related

C++ :: How To Properly Iterate Over A Container

Oct 31, 2013

so i have a container called Source that is of type std::map<std::string, std::vector<std::string>> but when I try to print it with this function:

void Lexer::PrintSource()
{
for(auto Iterator = this->Source.begin(); Iterator != this->Source.end(); Iterator++)
for(auto SubIterator = Iterator->begin(); SubIterator != Iterator->end(); SubIterator++)
cout<< *SubIterator << endl;
}

i get these errors:

Lexer.cpp: In member function 'void Lexer::PrintSource()':
Lexer.cpp:29:42: error: 'struct std::pair<const std::basic_string<char>, std::vector<std::basic_string<char> > >' has no member named 'begin'
for(auto SubIterator = Iterator->begin(); SubIterator != Iterator->end(); SubIterator++)
^
Lexer.cpp:29:76: error: 'struct std::pair<const std::basic_string<char>, std::vector<std::basic_string<char> > >' has no member named 'end'
for(auto SubIterator = Iterator->begin(); SubIterator != Iterator->end(); SubIterator++)
^

View 6 Replies View Related

C++ :: Variable Not Functioning Properly

Sep 29, 2014

#include <iostream>
using namespace std;
int main()
{

[Code]...

For some reason, I get the cout of

321
1

Because of the a++, shouldn't it be

321
2

The second example is what the cout needs to be.

View 1 Replies View Related

C# :: Parsing XML File Properly

Apr 11, 2014

I'm parsing an xml file full of payslips and using the data in another application. I've got it all working but I suspect it isn't the most elegant piece of code. I run through the xml file finding a series of "Text" attributes/elements" and then I run through it again finding a series of "Field" attributes/elements, Here is a sample of the code:

For getting the "Text" fields :

XNamespace ns = "urn:crystal-reports:schemas:report-detail";

//
// Get all the Text attributes & Elements
//
foreach (XElement xtxt in xdoc.Descendants(ns + "Text"))

[Code]...

This works fine, I extract all the data I'm interested in and go to do my thing with it. However I really need to know when each record ends and I was doing that by looking for "Text24" in the text fields and "EeRef2" in the field fields, which wasn't very elegant in the first place. Then a "Text16" was added to end of each record which was fine I could just look for "Text16" but now it's apparent that "Text16" isn't always there. I've got it all working for now but I'd prefer to process one record at a time i.e. extract all the "Text" & "Field" values for one record, do whatever I need to do with it, update the xml file to indicate this progress ( if possible ) and then move on to the next record. I've attached a sample of the xml but basically is has the following structure :

<Details>
<Section>
<Text></Text>
"
<Field></Field>

[Code]...

So a record is everything between the first <Details> and the last </Details> with two <Details> and two </Details> in between.

View 2 Replies View Related

C/C++ :: Threading / How To Invoke It Properly

Jun 12, 2012

I'm using MS' optimizing compiler CL 13.10 (one from VCToolkit 2003) along with WinAPI threading functions and is being compiled as a C console program.

I was wondering how to implement threading in a production setting? I've seen and tried various examples, but they all show basically the same thing - startup in main, run their function, clean up, and then the program exits.

I don't know the proper terminology, but I was looking for two maybe three functions to run simultaneously with a loop in main. I tried a small test program and was wondering if it's setup correctly.

A structure is used as the argument for each function.

int running = 1; // global variable  
DWORD WINAPI function_1(LPVOID);
DWORD WINAPI function_2(LPVOID);   
main() {  
   HANDLE hndThreads[2];
   DWORD threadIDs[2];

[code].....

Right now, function_2 is just a copy of function_1's definition. Everything *appears* to do what I want, but is it setup correctly?

View 2 Replies View Related

C++ :: How To Properly Use Pointer To A Particular Function

Apr 4, 2013

#include <iostream>
using namespace std;
int function(int a,int b) {
return a + b;
} bool function2(int a,int b)

[Code] .....

View 3 Replies View Related

C++ :: Print Function Does Not Work Properly

May 21, 2013

This is my code for submitting students but when i use search function the course member is empty

Code: #include "windows.h"
#include "iostream"
#include <io.h>
#include <sstream>
#include <conio.h>
#include <stdlib.h>
#include <iostream>
#define SIZE 5
using std::cout;
using std::cin;
using namespace std;
int menu();

[code].....

View 11 Replies View Related

C++ :: Checking If A Filestream Was Properly Opened

Apr 9, 2013

I' used to check if my streams are properly opened with a simple:

Code:
if (!file)
std::cout<<"Error message";

However I just realized this is only a valid test if they are initialized with a wrong string and when I tested it:

Code:
int main() {
ifstream f_one("input.txt");
ifstream f_two("not_a_file.txt");
ifstream f_three;

[Code] ....

I didn't get the f_three error message, only the f_two.

how should I check my streams in order to prevent this?

View 6 Replies View Related

C :: Qsort Function Won't Work Properly

Mar 20, 2013

i am facing some problem with qsort() function it work well if the last element of array is larger then the 2nd last element. But in case if last element of array is smaller then the 2nd last it will sort the whole array and remains the last as it is. For example

Code:
int group_id_local[max_j]={2,1,4,5};// it work fine, output should be {1,2,4,5} but if i have this one

int group_id_local[max_j]={2,1,4,3};
// output should be {1,2,4,3}
/* COMPARE FUNCTION FOR USING QSORT()*/
int cmpfunc (const void* a, const void* b)
{
if (*(int *)a < *(int *)b) return -1;
if (*(int *)a > *(int *)b) return 1;
return 0;

[Code]....

why it will not sort the last element?

View 5 Replies View Related

C :: How To Properly Put Char Values Into Array

Oct 24, 2014

I'm trying to fill the array "g" with letters from the array "letras" given a certain condition. Everything is working fine, except I couldn't do it... Strange characters appear when I run the code. What am i doing wrong?

Note: This is a part of a function. "vetor" is a parameter that was passed to this function.

Code:

int i;
int j = 0;
char g[20];
char letras[5] = {'a', 'b', 'c', 'd', 'n'};
while(j < g)
{
for(i = 0; i < 80; i = i + 4)

[Code]...

View 3 Replies View Related

C :: String As Parameter Not Working Properly

Oct 19, 2013

I want to alter a string inside a function, but it is not working.Here is the function:

Code:

#include <stdio.h>
void test (char *ch){
ch[0] = 0;
ch[1] = 1;
ch[2] = '';
}

[code]...

View 2 Replies View Related

C :: Labyrinth Creator Does Not Work Properly

Dec 16, 2013

this programm should in theory create a labyrinth but it doesnt and i really dont have the skill to pick up where i have been mistaken so gcc runs it but it crashes and it doesnt produce any remarkable results even when it runs....
for example this should you run it with these parameters .

5
5

appear something like this
10111
10101
10101
10001
11111

or like this

10111
10001
11101
10001
11111

but it only crashes....it works with recursion and it makes a array (which is Ptr) a set of 1 and 0 which 0 is the path and 1 is the walls...

Code:
#include <stdio.h>#include <stdlib.h>
#include <time.h>
int **Ptr;
int M, N, P, charge, i,c,j;
void Lab_creator(int vertical, int horizontal,int direction);

[Code] .....

View 2 Replies View Related

C++ :: Array Not Storing Values Properly

Jan 4, 2013

For some reason the integer array, arr[100][50], declared in main is not storing the correct values when passed through the function charArrayToIntArray.

I made an output right in the function to show how the array is not keeping the proper values, although when I output the array from within the loop in the function, it shows the correct values.

/*
infile.txt:
37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676 ...........

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cstdio>
#include <sstream>
#include <iomanip>

using namespace std;
void fileToCArray(string carr[100]); // from text file: inputs the 100 50-digits number into an array of 100 50-character

[Code] ....

View 4 Replies View Related

C++ :: How To Properly Cite A Source In Code

May 24, 2013

For example, if one researched how to deep copy a map container and paraphrased a solution from a website, what is the proper format? Are there standards for citing works in code?

I am currently only citing the link to the source in my personal code and explaining what algorithm the source contains.

View 4 Replies View Related

C/C++ :: Right Hand Maze Not Working Properly

Nov 1, 2014

I am creating a right hand maze solution, and it actually works for the most part, but it gets stuck at the sixth spot and will not proceed any further. I cannot seem to find my error even though I know it's probably a small one in my code, here is what I have at the moment:

#include "stdafx.h"
#include <iostream>
#include <Windows.h>

[Code].....

View 6 Replies View Related

C# :: How To Properly Handle Thread Failures

Feb 9, 2015

I have an application that uses an array of threads to call a method along with thread.join(). I was just wondering what would be the best way to handle the thread in case if one of the thread fails? Should I put a try catch block on the method that is being called or should I put the try catch block on the array of threads, or is there any other proper way to handle failed threads?

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved