Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 51 52 [53] 54 55 ... 91

Author Topic: Programming Help Thread (For Dummies)  (Read 100782 times)

Mephisto

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #780 on: October 01, 2012, 09:55:21 am »

Here I am, 9:45 on a Saturday night, working on class for a Master's in IT. Anyone have any Java Programming Questions? I am also experienced in PHP, Javascript and Drupal Development.

If you need a question, this one never got adequately resolved.

I'm trying to make a program that will check a yahoo email. However, when I do emailChecker.recieve(), it gives me an error message. I am using JavaMail. The code looks like this:

Spoiler: Code (click to show/hide)

And the error message looks like this:
Spoiler (click to show/hide)

Thanks in advance for the help.

Do you have a Yahoo Mail Plus account? Free accounts don't allow POP3 access.
Logged

Kofthefens

  • Bay Watcher
  • Keep calm and OH GOD CAPYBARAS
    • View Profile
    • Marshland Games
Re: Programming Help Thread (For Dummies)
« Reply #781 on: October 01, 2012, 06:44:17 pm »

I do not, that explains it. Any idea how to check a gmail account? (The tutorial I found was for yahoo mail, so I tried that).

Thanks!
Logged
I don't care about your indigestion-- How are you is a greeting, not a question.

The epic of Îton Sákrith
The Chronicles of HammerBlaze
My website - Free games

Silfurdreki

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #782 on: October 02, 2012, 06:34:54 am »

I am trying to make a (first) useful program in C. What I'm doing is that I'm trying to convert a binary image file of some strange format output by a CCD interface program (long story) into an ASCII table for further manipulation.

My problem involves reading the file in the first place. I have looked at several tutorials online but when I try to write similar code, it doesn't do what I want it to. So far I'm just trying out reading methods. Here's what I have so far:

Code: [Select]
#include <stdio.h>
int main(void)
{
FILE *file;
int close;
char in;
char out[11];
int i = 0;

file=fopen("c:\\test\\test.txt", "r");

while( (in = fgetc(file)) != EOF);
{
printf("%c", in);
out[i] = in;
i = ++i;
}

close = fclose(file);
printf("close = %d \n", close);

getchar();
return 0;
}

The program compiles and runs just fine, but it doesn't output anything. "test.txt" looks like this: "1 2 3 a b c", without quotes.

Also, I've seen the construct
Code: [Select]
int x[] to declare arrays in several tutorials, yet none explain what this means. I understand what x[10] or x[10] [10] means (a size 10 and a size 10 x 10 array, respectively). Finally, does x[10] give an array with elements 0-10 or an array with elements 0-9? I.e., does it give a 10 element array or an array with element 10 as its last element? Edit: Never mind, I just found this out myself.

Sorry for my extreme noobishness, but you've got to start somewhere, right?
« Last Edit: October 02, 2012, 06:37:03 am by Silfurdreki »
Logged
Quote
Entropy is not what it used to be.

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #783 on: October 02, 2012, 08:55:44 am »

The program compiles and runs just fine, but it doesn't output anything. "test.txt" looks like this: "1 2 3 a b c", without quotes.

Also, I've seen the construct
Code: [Select]
int x[] to declare arrays in several tutorials, yet none explain what this means. I understand what x[10] or x[10] [10] means (a size 10 and a size 10 x 10 array, respectively). Finally, does x[10] give an array with elements 0-10 or an array with elements 0-9? I.e., does it give a 10 element array or an array with element 10 as its last element? Edit: Never mind, I just found this out myself.

Sorry for my extreme noobishness, but you've got to start somewhere, right?

Okay so the reason is your ; after the while line. That will end the while loop there, its how single line while blocks work. Afterwards you have a scoped section that isn't actually realated to the while loop, at which point 'in' is -1.

Edit:
As an aside you don't need to say i = ++i;
++i; will already post increment the value of i, assigning it afterwards is just setting it to itself.
« Last Edit: October 02, 2012, 08:58:41 am by Shades »
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Silfurdreki

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #784 on: October 02, 2012, 09:54:45 am »

Thank you for the help! I found the problem on my own, though, but I appreciate it none the less.

I had a new problem, but it turns out your advice about not putting semi-colons after loop initializations were applicable there as well. :-[

What about the x[] array declaration? Does anyone have an explanation?
Logged
Quote
Entropy is not what it used to be.

Starver

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #785 on: October 02, 2012, 10:30:21 am »

Edit:
As an aside you don't need to say i = ++i;
++i; will already post increment the value of i, assigning it afterwards is just setting it to itself.
And you can also do "i++;", which I personally like (but YMMV).  Of course "i=i++;" might not be as useful. ;)


edit: Forgot to say (And I thought you'd said you'd found out) "x[]" is basically a "it's an array, but I'm not giving the size here".

Code: [Select]
// Defining an array of ten items (all set to zero, I /think/ - I rarely leave uninitialised arrays that way for long)
int x[10];
// Defining an array of ten items *and initialising with values*
int y[10] = { 1,1,2,3,5,8,13,21,34,55,89 };
// Defining an array of ten items *and initialising the first four, the rest will be zero*
int z[10] = { 2,4,6,8 };
// Defining an indeterminate array (not something I do often) with a determinate set of values
int u[] = { 1,3,7,9 };  // equivalent to int u[4] =  { 1,3,7,9 };

...assuming I'm not wrong.  I might be polluted with another computer dialect or language of what you're using.  But someone will correct me, if so.
« Last Edit: October 02, 2012, 10:52:20 am by Starver »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #786 on: October 02, 2012, 05:13:20 pm »

int array[] = otherarray;
only works in C#, methinks.

Codepad gives me this error:
Code: [Select]
In function 'int main()':
Line 9: error: initializer fails to determine size of 'a3'
compilation terminated due to -Wfatal-errors.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Shades

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #787 on: October 03, 2012, 04:05:41 am »

"x[]" is basically a "it's an array, but I'm not giving the size here".

Code: [Select]
// Defining an indeterminate array (not something I do often) with a determinate set of values
int u[] = { 1,3,7,9 };  // equivalent to int u[4] =  { 1,3,7,9 };

Pretty sure this is right, I can't remember when I last declared an array like that (I generally use c++ not c and so tend towards std::array)  but I'm pretty sure you can't only declare an array like this if your also defining the contents (as in Starvers' example) so that size is known at compile time. (which I believe is the error Skyrunner got)

You can do variably sized arrays with int *u = new int
  • ; where x is a variable defining the length at run time (as opposed to compile time). But then you get into the whole new/delete thing which is another thing I tend to avoid.


Edit: I appear to be unable to use forums....
« Last Edit: October 03, 2012, 09:39:59 am by Shades »
Logged
Its like playing god with sentient legos. - They Got Leader
[Dwarf Fortress] plays like a dizzyingly complex hybrid of Dungeon Keeper and The Sims, if all your little people were manic-depressive alcoholics. - tv tropes
You don't use science to show that you're right, you use science to become right. - xkcd

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: Programming Help Thread (For Dummies)
« Reply #788 on: October 03, 2012, 04:09:56 am »

I tend to use <vector>'s vectors. :D
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Chattox

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #789 on: October 03, 2012, 04:04:12 pm »

In C++, how would I go about getting different variable types from one file? For example, say the file's contents were like this:

derp
0.2
30

How do I get a string from the first line, a float from the next, and an int from the third?
Logged
"10 z levels down, 10 tiles north is some blood, i shall go clean it before it drives me to insanity with it's crimson color"
The setting of Half-Life 2 Episode 3's release: "It is the 41st Millennium. For more than a hundred centuries the Gabe has sat immobile on the..."

Soadreqm

  • Bay Watcher
  • I'm okay with this. I'm okay with a lot of things.
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #790 on: October 03, 2012, 05:41:19 pm »

Does C++ have any text parser functions? Because that's how I'd do it in Java. Read all three as strings, and then extract other values from the strings.
Logged

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: Programming Help Thread (For Dummies)
« Reply #791 on: October 03, 2012, 07:55:05 pm »

if the format is predictable (string, double/float, integer, etc) in a repeating pattern then you could write up your own parsing system. Read line, parse as first data type, increment data type to expect, read next line, continue and restart the data type counter whenever you reach the end of an entry.

I haven't played much in C++ lately, but that is the logic I'd use to make it work.
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Thendash

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #792 on: October 03, 2012, 08:03:13 pm »

Can the string contain characters? You could check to see if a char is present, if yes it's a string else numbers.
Logged
Thendash's Livestream

This game could honestly give out hand jobs for free and people would still bitch.

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: Programming Help Thread (For Dummies)
« Reply #793 on: October 03, 2012, 08:21:08 pm »

I believe that strings are treated as char constant arrays (probably misnaming) but you could do a quick check through string[index] -> string.Length (or some other magic) and come up with the answer.  So yes, it is my belief that you could do single character checks until either end of line or until you find a non-number character :D
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Thendash

  • Bay Watcher
    • View Profile
Re: Programming Help Thread (For Dummies)
« Reply #794 on: October 03, 2012, 08:41:53 pm »

Sorry I meant can the string contain numbers.
Logged
Thendash's Livestream

This game could honestly give out hand jobs for free and people would still bitch.
Pages: 1 ... 51 52 [53] 54 55 ... 91