David W 131 Practically a Posting Shark

Did you look at the two .txt files with a text editor?

There is something glaringly wrong with the 2nd longer file ... it seems quite corrupted, just a little way into it ...

Using an editor ... like notepad ... or programmers notepad ... take a look !

David W 131 Practically a Posting Shark

Perhaps the longer data file is too long to handle?

Try splitting it up into 1/2's and see if each 1/2, by itself, processes ok?

Is you output file looking correct for the smaller file that you said seems to run ok?

I would have thought your code would be more like this:

std::vector<SwingIdentified>::iterator SwingIter;

for (SwingIter= NamedSwings.begin(); SwingIter!=
NamedSwings.end(); SwingIter++)
outfile << *NamedSwings << std::endl;

David W 131 Practically a Posting Shark

Standard C and C++ do not support nested functions, but:
GCC supports nested functions in C, as a language extension...

https://en.m.wikipedia.org/wiki/Nested_function

Note: in C++, it seems you are limited in 'nesting classes' to ... you can 'nest' a class inside a class.

David W 131 Practically a Posting Shark

Is your expanded problem to process multiple files in a folder?

If so, then you could modify the example to be looking for the (input) .txt file names from standard input ...

Then ... perhaps ....
write a batch file, (that calls that compiled modified program .exe file), to process ALL the .txt files in that folder ...

After each file was processed, it would yield/output the corresponding .csv file.

David W 131 Practically a Posting Shark

Test this code:

// call string constructor
string test2( "good better best" );

// call istringstream constructor
istringstream is( test2 );

string x,tmp,z;
// extract words/strings from is object
is >> x >> tmp >> z;

// show best good backwards
cout << z << ' ' << x;

David W 131 Practically a Posting Shark

Can you test this code ?

cout << "Enter 3 words separated by a space: ";
string a,b,c;
cin >> a >> b >> c;
cout << "You entered: " << a << " and " << b << " and " << c << endl;

Do you see how the extraction operator >> works with a cin stream?

istringstream objects are 'string streams' that via the extraction operator >> you can extract strings (or other types) from the stream.

David W 131 Practically a Posting Shark

In C++ you need to write your own code to print out the elements of an array ...

string test = "a BB ccc";
istringstream iss( test );
string str[3];
iss >> str[0] >> str[1] >> str[2];
// try this ... or code a loop
cout << str[0] << ',' << str[1] << ',' << str[2];

David W 131 Practically a Posting Shark

iss >> tmp; //is getting the next line?

No ... getting the next item.

string test = "a BB ccc";
istringstream iss( test );
string str[3];
iss >> str[0] >> str[1] >> str[2];

What do you think is now in each array element?

Can you write a short program to test this out ... and see what happens?

David W 131 Practically a Posting Shark

Did you try out the working code I provided?

Did you read the comments in the code and try to follow the steps?

If you do not take time to read the instructions and follow them ... then why should I take any more time with you?

David W 131 Practically a Posting Shark

You have already been given a working C++ example solution ... if you are really sincere about learning to program in C++, then ... you really do need to start at the beginning ... as I previously indicated, and even provided some links to help you to start.

For example ... if I were to attempt to talk to you about 'entropy' and the 2nd law of thermodynamics ... before you had studied 'energy' ( / 'heat' / 'work' ) and the 1st law of thermodynamics ... and 'the atomic nature' of all matter ... and the concept of 'temperature' ... would you be able to understand and solve problems that related to the concept of 'entropy' ?

http://developers-heaven.net/forum/index.php/topic,2587.msg3103.html#msg3103

David W 131 Practically a Posting Shark

This code of yours:

string PK; // stands for primary key;
while ( getline( fin, line) && PK++ > 1);
PK = 98;

does NOT make any sense at all!

If PK is a C++ string,
then the default value (when constructed as you have coded)
is "", i.e. the empty string, and then this code:

PK++ makes NO sense at all!

But ...

PK += "Sam"; 
// this code makes sense, it 'concatenates' the string "Sam" 
// to the end of the empty string PK ... 
// so that PK then becomes "Sam" //

And then trying to compare a C++ string value to an int of value 1 ...
this reveals that you are really terribly mixed up,
and NOT understanding even C++ coding basics!

You need to start at the beginning and learn to program step by step.
(Study the 6 fast steps link I gave you previously ...)
There are many beginning C++ tutorials on line ...

Try this slower paced one:

http://developers-heaven.net/forum/index.php/topic,127.0.html

Where did you get this problem of extracting data from source files structured as you have suggested ... to produce the particular extracted csv data file you seem to want?

But take a look ...
this is how one might code a solution ...
after your last 'hint' ...
about the way the data is structured in the input data file:

// fileReadWrite3.cpp //  // …
David W 131 Practically a Posting Shark

Hint : the code might be a little simpler ... Read / discard 1st 3 lines ...
Then read a line ... and while exists next line and next line does not begin with "86" append to first line
Otherwise have first line of next rec... So process prev rec / 'extended line' and output the extracted data from this 'extended line'

David W 131 Practically a Posting Shark

NO!

This code: while( iss >> tmp && tmp.substr(0,3) != "333" ) ;
will be my reference I change 333 to 98, But I don't know where to put ...

NO!!! Leave that as is, since that was a part of your program data extraction specifications.

You need to think about what your program is supposed to do ... at each step ... and thus what edit(s) to make to example???

If you wish to process several files, each with the very same structure as the first, you could store the names in an array or an other C++ container like a vector, and then loop though each file name to process that file in turn ... while outputting processed data to files (or appending to a common output file if that was what you want.)

But ... get your code working perfectly ok for ONE representative example input file firstly !!!

David W 131 Practically a Posting Shark

The raw data file NEEDs to be 'massaged' to be regular to be read ok ...

IF these TWO lines are FIXED ...

It seems to be ALL read ok.

AUG.02, 2015
SMPH01 RPMM 020000
AAXX 02001
98132 31462 21101 10293 20264 40145 53020 70540 82100 33302 20255 56399 59004 82817 ='01
rh93/76 rmks 255 2am, fe.
98133 31467 20902 10300 20270 40109 5//// 70544 82200 222// 20501 33301 20255 56299 58002
82818 MJ. RMK.RH=90/80 MIN.=25.5 8AM
98134 32465 21002 10287 20253 39928 40114 53013 82200 33301 20250 56999 58002 82819 ='12
max=305@0600z min=250@1800z rh=87/79 MP
98222 31570 10201 10284 20242 40114 51007 70544 81200 33301 20249 56999 59002 81820 ='01
occurance of min. Temp. 2210z ca
98223 31460 21101 10288 20259 40103 52013 70540 81205 33301 20240 56999 58006 81819 ='08
RH 96/47 TMIN 24.0 @ 5:30 A.M. TAFOR RPLI 0606 32006KT 9999 FEW019 TEMPO 0612 32008KT 9999 FEW019 SCT100 RPLI 020000Z 11002KT 9999 FEW019TCU 29/26 Q1010 NOSIG RMK A2982 TCU W RPG
98232 31570 30000 10279 20246 30109 40112 53009 70500 81100 222// 20100 33302 20262 56999
58007 81820 RH92/65 MAX.TEMP.33.0@0600Z MIN.TEMP.26.2@2200Z REM.SLIGHT SEA ET'09
98233 31568 50000 10253 20234 40121 53024 70540 83230 33302 20240 56999 58010 83820 85358='08
T MIN = 24.0 @ 5:40 AM, MX RH = 90%, MN RH = 65% MLT
98324 11462 40901 10280 20251 40107 53013 60084 70544 82211 33312 20244 56929 58006 70084 82816
83358 CC MIN TEMP 24.4 AT 2100
98325 31462 31601 10278 20252 40101 53011 70592 …
David W 131 Practically a Posting Shark

You need to have the file it is looking for ... available.

For ease of access, place the file to be read in the same folder as your compiled .exe (executable) file.

Did you NOT see the comments ?

const char* FILE_IN  = "rawDataForExcel.txt";
const char* FILE_OUT = "selectedData.csv";
// example of 'in file'
/*
    AUG.02, 2015
    SMPH01 RPMM 020000
    AAXX 02001
    98132 31462 21101 10293 20264 40145 53020 70540 82100 33302 20255 56399 59004 82817 ='01
      rh93/76 rmks 255 2am, fe.
    98133 31467 20902 10300 20270 40109 5//// 70544 82200 222// 20501 33301 20255 56299 58002
     82818 MJ. RMK.RH=90/80 MIN.=25.5 8AM
    98134 32465 21002 10287 20253 39928 40114 53013 82200 33301 20250 56999 58002 82819 ='12
      max=305@0600z min=250@1800z rh=87/79 MP
    98222 31570 10201 10284 20242 40114 51007 70544 81200 33301 20249 56999 59002 81820 ='01
      occurance of min. Temp. 2210z ca
*/

The demo program, as above, IS looking for a file with the name:

"rawDataForExcel.txt"

So ...

Make sure a file with the above contents is there ... and called by that name!

David W 131 Practically a Posting Shark

You really do not need to read the processed records into a vector ...

I would keep it simple ... something like this:

// fileReadWrite.cpp //

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

using namespace std;

const char* FILE_IN  = "rawDataForExcel.txt";
const char* FILE_OUT = "selectedData.csv";

// example of 'in file'
/*
    AUG.02, 2015
    SMPH01 RPMM 020000
    AAXX 02001
    98132 31462 21101 10293 20264 40145 53020 70540 82100 33302 20255 56399 59004 82817 ='01
      rh93/76 rmks 255 2am, fe.
    98133 31467 20902 10300 20270 40109 5//// 70544 82200 222// 20501 33301 20255 56299 58002
     82818 MJ. RMK.RH=90/80 MIN.=25.5 8AM
    98134 32465 21002 10287 20253 39928 40114 53013 82200 33301 20250 56999 58002 82819 ='12
      max=305@0600z min=250@1800z rh=87/79 MP
    98222 31570 10201 10284 20242 40114 51007 70544 81200 33301 20249 56999 59002 81820 ='01
      occurance of min. Temp. 2210z ca
*/

struct CSV
{
   string ary[10]; // A,B,C,D,E,F,G,H,I,J; //

   // returns 0, or 1 if NEXT line is read in already //
   int extract( istream& fin, const string& str )
   {
       istringstream iss( str );
       string tmp;
       iss >> tmp;
       ary[0] = tmp.substr(0,2);
       ary[1] = tmp.substr(2);

       iss >> tmp;
       ary[2] = tmp.substr(0,1);
       ary[3] = tmp.substr(1,3);
       ary[4] = ary[5] = ary[6] = ary[7] = ary[8] = ary[9] = "x";

       for( int i = 0; i < 6; ++ i )
            iss >> tmp; // skip over 3,4,5,6,7 and read 8
       ary[4] = tmp.substr(0,1);
       ary[5] = tmp.substr(1,3);

       iss >> tmp;
       ary[6] = tmp.substr(0,1);
       ary[7] = tmp.substr(1,3);

       while( iss >> tmp && …
David W 131 Practically a Posting Shark

Show us the code you have tried so far ... for this:

You could read/skip the first 2 lines ... Then read (in pairs of) 2 lines, skipping over that first line and parsing the 2nd line ... till done ... You could use stringstream objects to ease parsing each line of numbers you wish to parse ... (as per the examples at the link provided.)

David W 131 Practically a Posting Shark

To start, you could look at the file read/parse examples here:

http://developers-heaven.net/forum/index.php/topic,2019.0.html

David W 131 Practically a Posting Shark

You could read/skip the first 2 lines ...
Then read 2 lines, skipping over that first line and parsing the 2nd line ... till done

You could use stringstream objects to ease parsing each line of numbers you wish to parse.

David W 131 Practically a Posting Shark

Do NOT use the above link ... because, the 'Hello World' example program there does NOT conform to standard C++ ... Standard C++ uses: "int main()"

#include <iostream>

//using namespace std;

int main()
{
    // your code goes here ... for example ...
    std::cout << "Hello World" << std::endl;

    // keep window open until 'Enter' key pressed ...
    std::cin.get();

    // if next line left off, the standard C++ compiler will add code
    return 0;
}

Note: the C/C++ main() function returns an integer

You may like to see the (pre C++11) examples here:

http://developers-heaven.net/forum/index.php/topic,2019.0.html

If you want to start out with C++14 ... you might like to see this also:

https://www.ebooks-it.net/ebook/beginning-c

by Ivor Horton

David W 131 Practically a Posting Shark

Do you know how to input a long C string?

In a loop, you could prompt (use printf) and then use fgets and a large char buffer (length pre-fixed at compile time) to input your test C string of a's and b's ... or you could use a readLine function to read in a dynamic C string of any length.

See this next link for an example of a readLine function:

http://developers-heaven.net/forum/index.php/topic,2580.msg2864.html#msg2864

Then just code using the hints you were given:

/* initial flags */
int a = 0, b = 0, c = 0;

Algorithm 1: Keep two binary flags, the a-flag and the b-flag. Every time an a is read, the a-flag is reversed (0 to 1, or 1 to 0); and every time a b is read, the b-flag is reversed. We start both flags at 0 and check to be sure they are both 0 at the end.

Algorithm 2: Keep only one binary flag, called the type3-flag. We read letter in two at a time. If they are the same, then we do not touch the type3-flag, since we have a factor of type1 or type2. If, however, the two letters do not match, we reverse the type3-flag. If the flag starts at 0 and if it is also 0 at the end, then the input string contains an even number of a's and an even number of b's.

David W 131 Practically a Posting Shark

Hi Pavan,

Being new at Daniweb, you may not know it is considered inappropriate to 'hijack' some one else's question. So ... please start a new 'thread' with your own question. It seems that your question here is similar to the original posters (OP's) question ... (and to many previous posters here at Dani's place) ... so please just search/read the replys already given ... or ask a new question in a new thread if your question is about a different subject matter. If you want help ... re. coding in C ... re. a solution to a particular problem, you need to firstly make your own best attempt at a solution and then show us the code that you have tried ... and where you think the problem is. Please note that there are very many free tutorials on the web re. 'Learning to Program in C' (or other programming languages - Please see the links provided above, for example.)

David W 131 Practically a Posting Shark

You might like to also see this:

Six Fast Steps to Programming in C

http://developers-heaven.net/forum/index.php/topic,2022.0.html

David W 131 Practically a Posting Shark

Your code would be so much more C++ like if you could follow the example of Dani's @NathanOliver ...

But if you really have to use C strings and pointers to char ... (in a C++ program) ...you could try something like this:

// split2.cpp //

#include <iostream>
#include <sstream> // re . istringstream object //
#include <string>
#include <vector>

#include <cstdlib> // malloc
#include <cstring> // re. strchr, etc... //

using namespace std;

// using stringstream objects //
void toToks( vector< string >& v, const string& line, const char delimit = '|' )
{
    istringstream iss( line ); // construct istringstring object 'iss' from string 'line'
    string tmpTok;
    while( getline( iss, tmpTok, delimit ) )
        v.push_back( tmpTok ); // push back a copy //
}

// using strchr and passing in C strings //
void toToks2( vector< string >& v, const char* line, const char delimit = '|' )
{
    const char* p1 = strchr( line, delimit );

    while( p1 )
    {
        int size = p1-line;
        char* str = (char*) malloc (sizeof(char) * (size+1));
        if( !str )
        {
            cout << "\nAn ERROR occured in calling malloc ...\n\n";
            return;
        }
        strncpy( str, line, size );
        str[size] = 0;

        v.push_back( str ); // push back a C++ string copy //
        free( str );

        while( *p1 && *p1 == delimit ) ++ p1;
        if( *p1 )
        {
            line = p1;
            p1 = strchr( line, delimit );
        }
        else break;
    }
}



int main ()
{
    cout << "Preferred 'method 1' using …
David W 131 Practically a Posting Shark

count frequency

Your title might have given you an hint about what was happening ...

Your goal seems to have been to find the frequency of each lower case letter in some input string ... lower case letters in the range 'a' to 'z'

Note also the 'hint' further provided to you here:

for (c = 0; c < 26; c++) /* Note mapping 0..25 to 'a'..'z' below */
{
    if (count[c] != 0) /* ONLY print letters with non-zero frequencies */
        printf("%c  %d \n", c+'a', count[c]);  /* print letter frequency */
}

Note also ... the well known dangers of buffer overflow using gets ... so much safer instead to use fgets

@Mir Mahfuz, we do hope you will put to good use and pass on your knowledge gained as you 'frequent' DANIWEB :)

David W 131 Practically a Posting Shark

My teacher say, that we should use stdio.h kg conio.h

stdio.h is commonly used for io (input/output) for programs in C, so you would be better to post this question in the DANIWEB C forum

Do NOT use conio.h if you want to code using standard C and thus to have portable code.

Can someone help me with this? "PROGRAM TO DISPLAY FACTORS OF A NUMBER"

Yes ... but firstly you need to make your own best attempt to code a solution and then to show us that code so we can see where you are at.

Use A1,A2,A3..as variables

NOT actually a good idea ... a better choice is to use variable names that describe what is being done.

Enter a positive integer: 60

int numIn;
printf( "Enter a number to find its factors: " );
scanf( "%d", &numIn );

/* now find & output all possible factors of numIn */

Factors of 60 are: 1 2 3 4 5 6 12 15 20 30 60

David W 131 Practically a Posting Shark

You might like to use some C++ library functions to assist parsing a line ...

http://developers-heaven.net/forum/index.php/topic,2019.msg2682.html#msg2682

David W 131 Practically a Posting Shark

See what you can code to take in data from a keyboard user (with suitable prompts) that could replace the code that takes in data from a data file.

David W 131 Practically a Posting Shark

Opps ... (typo fixed)

And instead of these includes :

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

Have these :

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <sstream> // re. istringstream object
David W 131 Practically a Posting Shark

You seem to have found the BP (Blood Presure) example program ok at the link I provided above ...

But ... note HINT!

If you read the (embedded) comments in that example program ...

// data file is structured like this ...
/*
Smith Jane 111/76
Jones Rob 98/70
Costello Judy-Ann 144/90
Frank-Anderson Bibby-Bonnie 190/30
Sue Peggy 10/5
James-Thomas Andrew 190/111
*/
const string MY_FILE = "BP.txt";

you would see a suggested starting set of 'test data'

that you might 'copy/paste into a file you call BP.txt

ALSO ...

please note the 'fix' code added below the exanmple to use instead of the code in the example.

i.e.

instead of :

// define overloaded >> for input of BP objects ...
friend istream& operator >> ( istream& is, BP& p )
{
    char skip;
    string scrap;
    is >> p.lname >> p.fname >> p.sys >> skip >> p.dia;
    getline( is, scrap );
    return is;
}

use this 'suggested fix' :

// define overloaded >> for input of BP objects ...
friend istream& operator >> ( istream& is, BP& p )
{
    string line;
    getline( is, line );
    istringstream iss( line ); // construct iss from line ...
    char skip;
    iss >> p.lname >> p.fname >> p.sys >> skip >> p.dia;
    return is;
}

And instead of just these includes :

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

Have this :

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <stream> // …
David W 131 Practically a Posting Shark

This is not actually a programming question (or rather, to solve this by simulating the behaviour of the robot is a bad way to solve this). This is a simple maths question. Solve it on paper first.

Actually, this is a good program to tackle by computer simulation ... as it makes you think about the many cases ... and assumptions one might make about the given initial conditions.

For example ...

  • can either ditch be reached by one forward move
    or one forward move followed by the backward move?
    If not, what constraint does this set upon all the initial givens?

  • if either ditch not reached in 'first moves' ...
    what does this imply about the meaning of (F-B) vs
    distance from inital spot to either ditch?

David W 131 Practically a Posting Shark

It also means that this code is many years out of date. Since C++11, there is an ifstream constructor that simply takes an object of type std::string

Unfortunately, it seems, many beginning students are still being asked to code to a C++ standard that is before C++11 ... so that their code can be compiled ok on standard C++ compilers pre C++11 ... but good to point out some of the nice things added ... in C++11 and C++14 versions ... as one feels may be appropriate to a beginning student.

Actually I have a question in my mind. Does the compiler makes the file itself we mention in the statement,or we have to create it first? like:
const string MY_FILE = "BP.txt";

You could use a text editor (copy/paste using an editor like Windows notepad) to make the test file I called "BP.txt"

And using save as ... save those data lines as BP.txt (in the same directory/folder as the executable file generated by your compiler.)

Make sure the file name is NOT saved as BP.txt.txt ... (if it is, rename it.)
Recall the example program is looking for a file with the name of BP.txt

David W 131 Practically a Posting Shark

Can you code a C++ program that prints a message to ask for input?
(Hint: look up: C++ cout)

Can you code to take in a number?
(Hint: look up: C++ cin)

Do you know how to use an if ... else if ...
structure in C++?
(Hint: look up: ...)

Ok ... now show us the code you have tried so far.

(Start out with just an 'Hello World' type C++ program that prints the first prompt ... and then add-code/compile-test ... as you go ...
from there ... in small increments of added code.)

David W 131 Practically a Posting Shark

Write a batch file to handle this ... then call that batch file.

David W 131 Practically a Posting Shark

Did you google for pdf file format?

But ... since the software you were using is NOT supported any longer ...
why not write your own data input forms?

David W 131 Practically a Posting Shark

Can you export your data base from Oracle to a spreadsheet like Excel ... as a csv file ... or csv files ?

If so, then you can easily code for a C++ program to input and parse each csv line from that file / those files ...

Put/parse each line into a C++ data record ( a C++ struct or class ) ...

Use a C++ container (a vector, or a ist, or a map) to hold each data record.

Then code for what you want to do with that data ...

But maybe, you might like to look at doing this is a (more) web friendly language like Python ?

David W 131 Practically a Posting Shark

In standard C you can create files ...

http://www.cplusplus.com/reference/cstdio/FILE/

http://www.cplusplus.com/reference/cstdio/fopen/

But ... I do not think there is a standard way to delete a file.

David W 131 Practically a Posting Shark

1) Get an up to date compiler (many are free like this one:

http://sourceforge.net/projects/orwelldevcpp/

2) Do not use conio.h ... or getche ... to keep code portable

3) Define your functions outside of main function ... before called

4) See example of how modern C++ looks ...

// hello.cpp //

#include <iostream>


void hello()
{
    std::cout<<"HI";
}


int main(void)
{
    hello();

    // keep 'window open' until 'Enter' key is pressed 
    std::cout << "\n\nPress 'Enter to continue/exit ... " << std::flush;
    std::cin.get();

    return 0;
}
David W 131 Practically a Posting Shark

If you were to google C++ file read / write you could find many code examples and articles to help ... ( also re. overloaded << and overloaded >> ) ...

Here is a link with several file read / write examples ... You might like to take a look at the BP (Blood Pressure) file read example especially:

http://developers-heaven.net/forum/index.php/topic,2019.0.html

David W 131 Practically a Posting Shark

As suggested above, this type of data record processing problem is handled much more easily and cleanly ...

by using a C struct (a data record)

and a readily expandable dynamic array ( a C vec with functions ) ...

Take a look ... and compare :)

Note, the 3 custom C utility functions used here are freely available ( see embedded links in example program below ) ...

/* CvecOfStructVersion.c */  /* 2015-08-03 */


/*
    Note: this 'solution' uses the 3 custom C utility files:
    readLine.h, Cvec.h, Cvec_func's
    Please see comments and links below to freely obtain copies ...
*/
#define EPSILON pow( 10.0, -6 )

#include <math.h>

#include "readLine.h"
/*
    NOTE! the include file readLine.h ... IS freely available at:
    http://developers-heaven.net/forum/index.php/topic,2580.msg2864.html#msg2864
*/

/* firstly define ... */
typedef struct myRec
{
    char* fname;
    char* lname;
    float score;
} Rec ;

void freeVrec( Rec* rc )
{
    free( rc->lname );
    free( rc->fname );
}

/* NOW .... ok to include ... */
#include "Cvec.h"
#include "Cvec_func's.h"
/*
"Cvec.h" is available at:
http://developers-heaven.net/forum/index.php/topic,2580.msg2862.html#msg2862
"Cvec_func's.h" is available at:
http://developers-heaven.net/forum/index.php/topic,2580.msg2866.html#msg2866
*/


void showRec( const Rec* rc )
{
    printf( "First name: %-20s Last name: %-20s Score: %5.1f \n", rc->fname, rc->lname, rc->score );
}
void showCvec( const Cvec* cv )
{
    int i;
    for( i = 0; i < cv->size; ++ i ) showRec( &cv->ary[i] );
}


/* next 2 functions are used in sorting the Cvec ... */
int cmpScores( const Rec* a, const Rec* …
David W 131 Practically a Posting Shark

Your Dev IDE settings ...
permit your code to be compiled using one of these standards ...

ISO C90  <--- this is what I normally choose when compiling C student code
ISO C99 
ISO C++     <--- this ... or if needed then ...
ISO C++ 11  <--- this ... is what I normally choose for C++ student code
GNU C90
GNU C99
GNU C++
GNU C++ 11

One question ... explain the term C++ 11 which I set in my compiler ... it's purpose?

If you use features in your code that are NOT available in a 'lower standard',
then that code will NOT compile ...
until ...
you turn on the ability to compile that code that uses those 'higher' features.

For example,
if you used [ ] with a 'lambda function' in some C++ code and used the ISO C++ compiler setting ...
it would NOT compile ...
until you reset the compile setting to one of the C++ 11 compile settings

David W 131 Practically a Posting Shark

Since I have not heard further ... I presume you have 'the example' working ok?

Here is a little upgrade to demo the ease of editing that code to a 'template'.

// CStack.h //  // 2015-08-03 //


// use a C++ 11 (or newer) compiler //

#include <iostream>
#include <string>
#include <stdexcept>

// using namespace std;

class cInvalidStack : public std::exception
{
protected:
    std::string msg;
public:
    cInvalidStack( const std::string& msg = "" ) : msg(msg) {}
    virtual std::string& what() = 0;
} ;



class cInvalidPush : public cInvalidStack // throw if stack is full
{
public:
    cInvalidPush() : cInvalidStack( "Stack is full." ) {}
    std::string& what() { return msg; }
} ; 

class cInvalidPop: public cInvalidStack // throw if stack is empty
{
public:
    cInvalidPop():cInvalidStack( "Stack is empty." ) {}
    std::string& what() { return msg; }
} ;



template< typename T >
class CStack 
{
public:
    CStack (const size_t stackSize = 10 ); 
    ~CStack();

    // copy ctor...
    CStack( const CStack& cstk )
    {
        top = cstk.top;
        max_size = cstk.max_size;
        ptr_stk = new T[max_size];
        for( size_t i = 0; i < top; ++ i ) ptr_stk[i] = cstk.ptr_stk[i];
        for( size_t i = top; i < max_size; ++ i ) ptr_stk[i] = T();
    }
    // overloaded operator ==
    CStack& operator == ( const CStack& cstk )
    {
        if( this != &cstk )
        {
            delete ptr_stk;

            top = cstk.top;
            max_size = cstk.max_size;
            ptr_stk = new T[max_size];
            for( size_t i = 0; i < top; ++ i ) ptr_stk[i] = cstk.ptr_stk[i];
            for( size_t …
David W 131 Practically a Posting Shark

re. 2)
tools
compiler options
settings
code generation
compile width ... pointer width ... select 64 bit

re. 1)
tools
compiler options
settings
code generation
language standard ... select either C++ 11 option

And while your setting up your compiler turn on warnings (click on):
tools
compiler options
settings
code generation
warnings
select ... these 3 ... -Wall, -Wextra, -pedantic

David W 131 Practically a Posting Shark

With your Dev compiler ...

1) make sure you HAVE pre-set ... to compile as C++ 11

2) make sure the pointer width is 64 bit

3) make sure to compile with 64 bit release

Other settings than the above seem to be problematic with your Dev compiler

David W 131 Practically a Posting Shark

This 'question' may be a little 'stale' by now,

but an edit/fix of the OP's code,

may serve as a demo for other C students

who stop in at Dani's fav student place,

The following C code is an example of how pointer arithmetic

could be used exclusively in a C program (as per the original spec's.)

Enjoy :)

P.S.

The use of parallel (arrays) blocks of (contigious) memory is 'old school'
and code for a soulution to this problem
would be much clearer/simpler
if a C struct (data record) was used instead (of parallel arrays)

And ... using a Cvec of struct would further simplify the code ...
and make the logic flow clearer ...
and thus ... much easier to code/maintain.

Re. file "Cvec.h" ...
see:
http://developers-heaven.net/forum/index.php/topic,2580.msg2862.html#msg2862

/* pointers_only.c */  /* 2015-08-02 */


/*
    A demo of using exclusively C pointer arithmetic
    for all blocks of memory ...
    and all items stored in those blocks memory.

    Note: this 'solution' uses the custom C utility file:
    readLine.h
    Please see comment and link below to freely obtain a copy.
*/

#include <math.h>

#include "readLine.h"
/*
    NOTE! the include file readLine.h ... IS freely available at:
    http://developers-heaven.net/forum/index.php/topic,2580.msg2864.html#msg2864
*/



#define EPISILON pow( 10.0, -6 )

#define MEMERR "There was a problem allocating memory."


/* 2 handy utilities for many C student coding problems ... */
int takeInChr( const char* msg )
{
    char chr;
    printf( msg ); fflush( stdout ); …
David W 131 Practically a Posting Shark

Did you see the other post with fixes/edits to your code ?
Please mark that (primary post) as 'solved' ... and in the future, please try to avoid 'duplicate posts' :)

David W 131 Practically a Posting Shark

You may like to see this ...
(uses some freely available custom C utility files ...
so see the comments for links to files needed in the example program.)

/* parseDataFile2.c */

/*
    NOTE! the include file readLine.h ... IS available at:
    http://developers-heaven.net/forum/index.php/topic,2580.msg2864.html#msg2864
*/

#include "readLine.h"

const char* FNAME = "test_ud.txt";
/*
    IP:192.168.0.1 DLD:123451
    IP:192.168.0.2 DLD:123452
    IP:192.168.0.3 DLD:123453
    IP:192.168.0.1 ULD:123454
    IP:192.168.0.2 ULD:123455
    IP:192.168.0.3 ULD:123456 //No new line after last entry//
*/

/* firstly define these ... */

typedef struct MyData
{
    char* paddr;
    char direction; /* 'u' or 'd' */
    int data;
} Rec;

#define DataInfo Rec

/* NEED to define ... so can free dynamic memory in Cvec */
void freeVrec( DataInfo* p )
{
    free( p->paddr );
}

/*
    NOW can include file Cvec.h ... available at:
    http://developers-heaven.net/forum/index.php/topic,2580.msg2862.html#msg2862
    and file Cvec_func's.h ... avaliable at:
    http://developers-heaven.net/forum/index.php/topic,2580.msg2866.html#msg2866
*/
#include "Cvec.h"
#include "Cvec_func's.h"


void showRec( const DataInfo* di )
{
    printf( "%20s, %c, %10d\n", di->paddr, di->direction, di->data );
}
void print( const Cvec* cv )
{
    int i = 0;
    for( ; i < cv->size; ++ i ) showRec( &cv->ary[i] );
}


void parseLine( const char* line, DataInfo* di )
{
    char* p = strchr( line, ' ' );
    if( p )
    {
        di->paddr = newsubstr( &line[3], 0, p-(line+3) );
        di->direction = *(++p);
        di->data = atoi( &p[4] );
    }
    else
    {
        printf( "Data error in file %s\n", FNAME );
        di->paddr = newsubstr( line, 0, my_strlen( line ) );
        di->direction = '?';
        di->data …
David W 131 Practically a Posting Shark

Since you have supplied the most part of the code ... you might like to see this little further 'edit' that might help you to continue ...

Edit: use a C++ 11 or greater compiler

// CStack.h //


#include <iostream>
#include <string>
#include <stdexcept>

// using namespace std;

class cInvalidStack : public std::exception
{
protected:
    std::string msg;
public:
    cInvalidStack( const std::string& msg = "" ) : msg(msg) {}
    virtual std::string& what() = 0;
} ;



class cInvalidPush : public cInvalidStack //exception if stack is full
{
public:
    cInvalidPush() : cInvalidStack( "Stack is full." ) {}
    std::string& what() { return msg; }

} ; //end class

class cInvalidPop: public cInvalidStack //exception if stack is empty
{
public:
    cInvalidPop():cInvalidStack( "Stack is empty." ) {}
    std::string& what() { return msg; }

} ; //end class




class CStack // holds the prototype of functions //
{
private:
    int* ptr_stk; //points to an array of integer
    int top; //contains the index value of array from where the value will be pushed and poped
    int max_size;
public:
    CStack (const int stackSize = 10 ); //default size for the stack is 10
    ~CStack();

    void push( const int ); //push the value in array of integers pointed by int *ptr_stk
    int pop();  //pop the value array of integers pointed by int *ptr_stk from the top of stack

    int isFull() const; //returns 1 if stack is empty otherwise 0
    int isEmpty() const; //returns 1 if stack is full otherwise 0
    int size() const { return top; } // …
David W 131 Practically a Posting Shark

You may like some fixes/edits ... as per the following 3 files:

file 1:

// BankAccount.h //

#include <string>

class BankAccount
{
    public:
        BankAccount( const int accNumber, const std::string& accName );

        void setAccNumber( const int accNumber );
        int getAccNumber() const;

        void setAccName( const std::string& clientName );
        std::string getAccName() const ;

    protected:
        int mAccNumber;
        std::string mAccName;

} ;

BankAccount::BankAccount( const int accNumber, const std::string& accName )
    : mAccNumber(accNumber), mAccName(accName) {}


void BankAccount::setAccNumber( const int accNumber )
{
   mAccNumber = accNumber;     
}

void BankAccount::setAccName( const std::string& accName )
{
    mAccName = accName;
}

int BankAccount::getAccNumber() const
{
    return mAccNumber;
}

std::string BankAccount::getAccName() const
{
    return mAccName;
}

file 2:

// BankDatabase.h //

#include <map>
#include <iostream>
#include <stdexcept>

#include "BankAccount.h"


class BankDatabase
{
    public:
        BankDatabase();

        void addAccount( const BankAccount& acc );
        void deleteAccount( const int accNumber );

        BankAccount& findAccount( const int accNumber ) throw ( std::out_of_range );
        BankAccount& findAccount( const std::string& accName ) throw ( std::out_of_range );

        void mergeDatabase( BankDatabase& db );

    protected:
        std::map< int, BankAccount > mAccounts;

    friend std::ostream& operator << ( std::ostream& os, const BankDatabase& db )
    {
        for( auto i : db.mAccounts ) os << i.second.getAccNumber() << ", " << i.second.getAccName() << '\n';
        return os;
    }
} ;


BankDatabase::BankDatabase(){}

void BankDatabase::addAccount( const BankAccount& acc )
{
    if ( ! mAccounts.count( acc.getAccNumber() ) )
       mAccounts.insert( std::pair<int, BankAccount > ( acc.getAccNumber(), acc ) );
    else
        std::cout << "Account '" << acc.getAccNumber() << "' exists already so can NOT be created ...\n";
}

void  BankDatabase::deleteAccount( const int accNumber ) …
David W 131 Practically a Posting Shark

Opps in avove ... (forgot this was C forum)

C code could be like this:

if( fin )
{
    char str1[132], str2[132];
    int intVal = 0;
    while( fscanf( fin, "%s %s %d ", str1, str2, &intVal ) == 3 )
    {
        /* proccess data and show desired output*/
    }
    fclose( fin ); 
}
else /* print error message re problem opening file *

If the customer ID is a varaible number of char's (BUT NOT ANY DIGITS) ...
you could find the index of the first digit in that C string
and then take the sub-string (till there) ...