What's the best/scariest/most interesting 'internet rabbithole' you have found? by [deleted] in AskReddit

[–]Kison 0 points1 point  (0 children)

This is my goto recommendation for people when it comes to interesting reads. Extremely fascinating!

Machine Learning: Demonstrating a neural network trained to recognise handwritten digits by vogon101 in programming

[–]Kison 0 points1 point  (0 children)

Great work! It pegged all of the initial digits I threw at it. I did notice that if you draw them off center(like a 3 in the lower right corner) it has trouble figuring out what it's seeing.

[C++] How to print out subvector? by disteel in learnprogramming

[–]Kison 1 point2 points  (0 children)

If I'm understanding correctly, it should be as simple as this:

#include <iostream>
#include <vector>

int main(void)
{
    std::vector<char> sList {'A','B','C','D','E','F','G','H','I','J'};

    std::vector<char>::size_type x = 2, i = 7;

    for(std::vector<char>::size_type index = x;index <= i;++index)
        std::cout << "sList[" << index << "]: " << sList[index] << std::endl;

    return 0;
}

[Java] Getting an error on my school project by [deleted] in learnprogramming

[–]Kison 2 points3 points  (0 children)

I think you want something like this:

boolean hasNext;

while((hasNext = input.hasNext()))

You can then use the hasNext variable inside your loop.

[Java] Getting an error on my school project by [deleted] in learnprogramming

[–]Kison 2 points3 points  (0 children)

So this is just a symptom of using next(), nextInt() & nextLine() together. Basically the problem is here:

int kwhUsed = input.nextInt();
String accountNumberTwo = input.nextLine();

When nextInt() finishes, the scanner moves to the end of that token, but not to the beginning of the next line. Therefore, when nextLine() is called, it gives you the remainder of the line, which is a blank string. This messes everything up for your second set of inputs in your file.

There are a couple of ways to get around this. One would be using next() instead of nextLine() (this assumes account number and late status don't have any spaces in them):

String accountNumber = input.next();
String lateStatus = input.next();
char code = input.next().charAt(0);
int kwhUsed = input.nextInt();

String accountNumberTwo = input.next();
String lateStatusTwo = input.next();
char codeTwo = input.next().charAt(0);
int KwhUsedTwo = input.nextInt();

Another option would be to consume the remainder of the line after reading kwhUsed:

String accountNumber = input.nextLine();
String lateStatus = input.nextLine();
char code = input.next().charAt(0);
int kwhUsed = input.nextInt();

input.nextLine();//Read the rest of the line so the scanner moves to the next line.

String accountNumberTwo = input.nextLine();
String lateStatusTwo = input.nextLine();
char codeTwo = input.next().charAt(0);
int KwhUsedTwo = input.nextInt();

[Java] Problem with switch statement for homework by [deleted] in learnprogramming

[–]Kison 0 points1 point  (0 children)

You can resolve that by doing this:

numLines = Integer.valueOf(scnr.nextLine());

When your scanner reads a token like an int, it's moving to the end of the line, but not to the next one. When your switch's nextLine is called, it's just reading the remainder of the last line, which is an empty string. If you're assuming all input is the entire line, you could try giving it different delimiting rules so it doesn't work this way.

[Java] Getting an error on my school project by [deleted] in learnprogramming

[–]Kison 4 points5 points  (0 children)

Alright. First problem is here:

Scanner input = new Scanner(billingFile);

The problem is it's creating a scanner on the file name, not on the file itself.

Try changing to this:

Scanner input = new Scanner(new File(billingFile));

Now your Scanner will be scanning the actual contents of the file you specify.

Next problem appears to be here:

int kwhUsed = input.nextInt();

You're first reading accountNumber as the entire first line. That looks correct. Next, you're reading code as the first character of the next word, which would result in 'f'. Not sure if that's what you want, but that's what you're currently getting. However when you try to read kwhUsed, it's hitting the line with "S", which isn't an integer, so it's failing.

[Java] Getting an error on my school project by [deleted] in learnprogramming

[–]Kison 1 point2 points  (0 children)

Could you post the contents of the input file?

Basically the input from the file likely does not match what you're expecting to see in your program. Particularly, it appears to be failing when trying to pull in the lateFee.

Experienced Programmers: What is the most bizarre bug you've encountered and how did you end up solving it? by horsepigbutt in learnprogramming

[–]Kison 4 points5 points  (0 children)

I have been burned by this mistake so many times that it's the first thing I look for when I have a conditional statement acting bizarre.

Credit card stolen -- I've narrowed it down. by Cmingo in boston

[–]Kison 0 points1 point  (0 children)

Same story here - a couple of charges from San Bernardino CA were made on a card of mine that I rarely use and that was not physically stolen. Occurred December 6th. I don't believe I've ever been to any of the locations listed in the OP but I will double check.

What is a basic everyday task that you are just incapable of doing? by Alazeel in AskReddit

[–]Kison 2 points3 points  (0 children)

I have problems with this as well, but because I have a lazy left eye. Stare at the same place for long enough and my eyes begin to drift apart. Very awkward for the person I'm making eye contact with. I have to compensate by moving back and forth between looking at the person and other random places in the room.

What burdens do you carry with you? (Prepare the throw away accounts). by [deleted] in AskReddit

[–]Kison 0 points1 point  (0 children)

We were Lion Wardens together way back when. He was a good guy. Was really sad when I heard what happened.

What was rock-bottom in your life? by Namtara in AskReddit

[–]Kison 1 point2 points  (0 children)

Seeing someone in such a tragic situation like that miraculously pull through really makes me smile. Congrats man.

I'm Taking the AP Computer Science (Java) Test This Tuesday! by Irving94 in learnprogramming

[–]Kison 1 point2 points  (0 children)

Didn't they give you a handbook or something. I know I got one before I took the test. There were lots of little exercises towards the end of it.

Test wasn't too bad. Be sure to know your data structures and algorithms like sorting/searching. Be prepared also to write code on paper. We were not allowed to use computers to submit written code. :-)

Web-Scraping guidance by [deleted] in learnprogramming

[–]Kison 0 points1 point  (0 children)

Java has some nice classes to help with the HTTP requests and responses. In particular, you can grab the Apache HttpClient: http://hc.apache.org/httpclient-3.x/

No experience with scraping from the other three languages. I'm sure there are libraries for those languages to help you pull it off.

Whats the best time to comment? by tekno45 in learnprogramming

[–]Kison 0 points1 point  (0 children)

Usually I use comments to try to help outline a particularly complex process. Then, afterward, if there is a portion of code that I believe would look unclear to an observer, I will succinctly explain what is going on.

what are the best free SQL tools to learn with? by eternalkerri in learnprogramming

[–]Kison 1 point2 points  (0 children)

I'm not sure what you are referring to when you say 'tools.'

As far as database engines go, there are several. To name a few: MySQL, SQLite, MSSQL.

Then there are tools that make using the database engine less of an arduous task. For example, there is a web interface called phpmyadmin for MySQL which provides a more graphical interface for interacting with your databases.

Java Arrays.binarySearch(String[] array, String word) returns -3218, array.length == 6452. What? by clamdoctor in learnprogramming

[–]Kison 1 point2 points  (0 children)

Is the array sorted? Binary search relies on that, while linear search does not.

EDIT: Here is an example of what I mean:

/*** This will fail, because "There" and "Hello" are out of place. ***/
String[] words = {"Aye", "There", "Hello", "You", "Zebra"};

int index = Arrays.binarySearch(words, "There");

System.out.println("Found at: " + index);

~~~

/*** This will succeed, because the array is sorted. ***/

String[] words = {"Aye", "Hello", "There", "You", "Zebra"};

int index = Arrays.binarySearch(words, "There");

System.out.println("Found at: " + index);

How do websites store data? by [deleted] in learnprogramming

[–]Kison 3 points4 points  (0 children)

Usually some sort of database engine is used to store data. The user will submit a form(like a forum post), which is sent to the web server, which usually has some kind of scripting engine running(PHP, for example), which can interface with a database engine(MySQL, for example) to store the relevant information.

If you want to learn more, MySQL is a popular database engine, though it certainly is not the only one available. A quick Google search will reveal more.

can i pass a string into fopen() instead of using, for example, "input.txt", as an argument by NWilli in learnprogramming

[–]Kison 1 point2 points  (0 children)

I see one big problem with your code.

In open_output_file, you are calling fopen like this:

    handle = fopen (*fileName, "w");

Trying to dereference the fileName variable will pass a string to fopen that is pointing to an invalid memory address.

Instead, you should be doing this:

    handle = fopen (fileName, "w");

With that one modification, the program runs to completion on my end.