DGPickett 20

Not seeing a lot of morphine, just a loop, a few ints, some io!

DGPickett 20

Generally, when you go to a web site without a valid timed login cookie, the server redirects you to the login page, possibly with a cookie or variable saying where to go (the original page) after login.

DGPickett 20

If you open an output ofstream and use it not cout, the data is saved in a file.

DGPickett 20

EOF check between read and write, use get() to pick up white space characters, getline() removes the lew line.

dgp@dgp-p6803w:~
$ myCC c++rw
dgp@dgp-p6803w:~
$ c++rw
Type in file name followed by the extention ".txt"
x.txt
File created.
Please enter text: 
hohoho
File Information: hohoho
dgp@dgp-p6803w:~
$ 

#include <iostream>
#include <fstream>
#include <sstream>
#include <string> 
using namespace std;
int main()
{
    cout << "Type in file name followed by the extention \".txt\"" << endl;
    string user_file;
    getline( cin, user_file );
    fstream file; //object of fstream class
   //opening file "sample.txt" in out(write) mode
    file.open(user_file, ios::out);
    if (!file)
    {
        cout << "Could not open file" << endl;
        return 0;
    }
    cout << "File created." << endl;
    //write text into file
    string user_input;
    cout << "Please enter text: \n";
    getline(cin, user_input);
    file << user_input << endl ;
    //cout << "For testing. User input is: " + user_input<< endl;
    file.close();//close the file
    //system("pause");
    //open file to be read
    file.open(user_file, ios::in);
    if (!file)
    {
        cout << "Could not open file" << endl;
        return 0;
    }
    char ch; //read character
    cout << "File Information: ";
    while ( true )
    {
        file.get( ch );
    if (file.eof())break;
        cout << ch;
    }
    file.close(); 
    return 0;
}

DGPickett 20

Lots of references on the dangers and costs of various equalities. This one seems very nice: https://www.mattzeunert.com/2016/01/28/javascript-deep-equal.html

DGPickett 20

I have had good luck with:

"<HTML><HEAD><TITLE>My Title</TITLE>...</HEAD><BODY>...</BODY></HTML>"

DGPickett 20

Wow, I just write a service that runs the query and reformats the column titles and values into an HTML table. If I wanted it to be more spreadsheet-like, there are caned javascript bits out there to allow you to re-sort the table.

DGPickett 20

There is consulting, where they run interference for you, freelance work, volunteer work, teaching, tutoring and open source collaboration to get your status up and your skills sharp.

DGPickett 20

Hash tables are containers. Hashing creates an integer from other types, usually the characters of a key, where it represents the values and positions of those characters. One divides the hash by the bucket count to select a bucket, which is a simple container like linked list where you can search for a precise match. One item per bucket is unwise! The cost of a bucket is a pointer, or 4/8 bytes, so use lots of buckets. Mod-2 bucket counts can be mod by simple and-masking out the lower bits, and the bucket count can be doubled (linear hash table) but the misplaced copied items must be culled or tolerated. Non-mod-2 bucket counts may randomize better! Hash is faster than tree, hash generate/divide cost being less than log2 comparisons, but it is not sorted. Other containers are the skip list: a tree-linked-list hybrid, the trie (a tree with one level per key character), the array and the linked list. Each has its advantages. The linked list adds/expands cheaper. Array lists always know their size, but are expensive to add or delete intermediate values. Linked list search/delete/insert requires comparing half the items on average. Lists are often used as queues in multithreaded situations, and one needs to decide on a fixed size or expensive expansion times, anticipate locking costs, thread suspension costs.

rproffitt commented: I love this. Just the thing to read to a class and then hand out the quiz. +15

DGPickett 20

Maybe put the array and indexes in parens after the & ? Debug messages on stderr , which, unlike stdout, is unbuffered!

DGPickett 20

There are just 4 rules to parsing a CSV:
Commas separate fields
Carriage return linefeed separates rows
Unless inside “
But “” is a literal “

DGPickett 20

To read a file, you need to declare an ifstream, open it, read from it using using >> into the appropriate types and check for eof(), bad(), fail() to detect errors and end of file. Note that >> at EOF sets fail (you didn't get what you asked for) as well as eof but not bad.

Putting the data into parallel arrays is pretty easy. Declare an array for each of the 3 items, and load it as you read using the same index. The arrays need to be big enough or you need to dynamically size them, google for examples.

DGPickett 20

Comparing null terminated char arrays is:

#include <string.h>
int strcmp(const char *s1, const char *s2);

but for known length unterminated strings:

   #include <string.h>
   int memcmp(const void *s1, const void *s2, size_t n);

Both return an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than the first n bytes of s2. Beware: other comparisons do other things, useful in other cases! For instance, for case insensitive null term string comparison:

   #include <strings.h>

   int strcasecmp(const char *s1, const char *s2);

DGPickett 20

The keyboard and monitor data is 'cooked', not raw, unless you turn on raw orocessing like with stty in UNIX. The enter key is a carriage return 0x0D or ctrl-M, but is cooked into carriage return and linefeed 0x0D0A ctrl-M ctrl-J. On the teletype, one makes the typehead go to the left end (slower, so a head start), the other makes the paper roller move (still slow).  A monitor emulates a tty printer. The real tty needed padding characters to allow time for the motions, too! See 'man stty'!

DGPickett 20

There may be integration to get the drivers and decoders onto the same die as the LEDs, but yes, otherwise, 3020 connections x 3 (R G B) and a very fast scan rate. Any my TV is 4K, not 1080. I suspect they may be driving more than one dot at a time, as 16 (for 4k is 16 x as many pixels) x 1080 x 1940 x 59.98 Hz = 2 GHz, but maybe -- chips are so fast these days. All three colors need to be driven at once, I expect. Pixel intensity can be modulated by voltage or time of the pulse, and varying the timing or voltage at high scan rates is hard.

DGPickett 20

For masking, write the random numbers directly, not as ascii. Write with fwrite() so each number is buffered into large block writes. Note that RAND_MAX is just 31 bits:

/usr/include/stdlib.h:#define RAND_MAX 2147483647

You can write 3 bytes at a time to have pure randomness. Remember that the bytes you want are located at different ends on little-endian hosts like x86 and big-endian hosts like SPARC. The middle 2 bytes are safe!

I would think that, for masking old data, a random block of a handy size like 65536 would suffice, written over and over to make a large file. More masking on magnetic media takes more write passes with different random data.

Many write passes might shorten SSD life, but I do not think SSD data are possible to recover after a rewrite.

Depending on the file system, you may be limited to 4GB files, but just open a new file and keep on. Systems may get unstable if there is no space left on the primary disk partition, so automated deletes immediately at write error would be nice.

MosaicFuneral commented: Thanks man. That's legit good advice. +11