• What do you need help with? V4 (January 2012)
    966 replies, posted
Hey guys, I decided to learn how to code for the first time, so I began learning some C# yesterday. I'm having trouble assigning the number the user inputs to an integer (a and b): [code] static void Main(string[] args) { Console.WriteLine("Welcome to the formula application! Which formula would you like to use?"); Console.WriteLine(@"a: Pythagora's Theorem b: Unexisting"); ConsoleKeyInfo info = Console.ReadKey(); if (info.KeyChar == 'a') { int a, b; Console.WriteLine("Pythagora's Theorem is a^2 = b^2 + c^2"); Console.WriteLine("a = ?"); Console.ReadLine(); a = info.KeyChar; if (a < 0) { Console.WriteLine("a can only be positive!"); Console.ReadLine(); a = info.KeyChar; } Console.WriteLine("b = ?"); Console.ReadLine(); b = info.KeyChar; if (b < 0) { Console.WriteLine("b can also only be positive!"); Console.ReadLine(); b = info.KeyChar; } double squareRoot = Math.Sqrt((a * a + b * b)); Console.WriteLine("c = {0}", (a * a + b * b)); Console.ReadLine(); } if (info.KeyChar == 'b') { Console.WriteLine("Haven't inserted a second formula yet, just hold on."); Console.ReadKey(); } } [/code] c is always 18818 in the pythagora's theorem part. Is this number a magical one or something?
you need to read user input each time, it won't automatically update the info variable. a = int.Parse(Console.ReadLine());
How could I count how many spaces are in a txt file?
[QUOTE=Edvinas;34663837]How could I count how many spaces are in a txt file?[/QUOTE] [code]#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { if (argv[1]) FILE *in = fopen(argv[1], "r"); int c, spacect = 0; while ((c = getc(in)) != EOF) spacect += (c == ' '); printf("Total number of spaces: %d\n", spacect); return 0; }[/code] [editline]12th February 2012[/editline] This is the quick and dirty solution, if it's a very large text file then it probably will be better to read it into a buffer in blocks and loop through those to check for spaces.
Thank you.
[QUOTE=Cuel;34647448]bind it to a keypressed or keyreleased event[/QUOTE] Thanks, however, it seems everyone skipped over the first part of my question, so... In java, I have a JFormattedTextField with an ActionListener added to it and utilizing this simple Mask Formatter: format=new MaskFormatter("####"); It works, but the ActionListener wont perform unless I've filled all four of the digits in the text field. I want it to take any integer with [i]up to[/i] four digits, not only four. Anyone know how to do this? I've been looking around and it looks like I may just need a normal JTextField with a custom Document, but I don't yet know how to write one of those. So, if that is indeed the only solution, if anyone could give me a link(s) to a good resource(s) for writing documents for text fields I'd really appreciate it.
Any of yall folks work with Arduinos before? [editline]12th February 2012[/editline] When I get my files I'll present my problem.
[QUOTE=laharlsblade;34665480]Thanks, however, it seems everyone skipped over the first part of my question, so... In java, I have a JFormattedTextField with an ActionListener added to it and utilizing this simple Mask Formatter: format=new MaskFormatter("####"); It works, but the ActionListener wont perform unless I've filled all four of the digits in the text field. I want it to take any integer with [i]up to[/i] four digits, not only four. Anyone know how to do this? I've been looking around and it looks like I may just need a normal JTextField with a custom Document, but I don't yet know how to write one of those. So, if that is indeed the only solution, if anyone could give me a link(s) to a good resource(s) for writing documents for text fields I'd really appreciate it.[/QUOTE] what are you trying to do? have the users only input digits?
[QUOTE=robmaister12;34662141] Flip the 2nd and 3rd rows, set the 3rd row negative. [1, 0, 0, 0] [0, 0, 1, 0] [0, -1, 0, 0] [0, 0, 0, 1][/QUOTE] Thank you for that. However I forgot a key detail: You can't multiply a vector by a matrix. Should I manually flip my normal/position vectors, and then convert my rotation to a 4x4 matrix, multiply that by this matrix? (I currently convert from Euler Radian Angles to a Quaternion to a 4x4 matrix which is then multiplied by a translation matrix which is inverted and saved)
You can multiply a vector by a matrix, it's how OpenGL and DirectX transform your vertices to clip space. If you're using OpenTK or XNA (and probably a lot of other libraries), the functionality is exposed as "Vector4.Transform", if you're using your own math classes, look up some guides on how it's done, but essentially you just view the vector as a 4x1 matrix and do standard multiplication.
[QUOTE=robmaister12;34670027]You can multiply a vector by a matrix, it's how OpenGL and DirectX transform your vertices to clip space. If you're using OpenTK or XNA (and probably a lot of other libraries), the functionality is exposed as "Vector4.Transform", if you're using your own math classes, look up some guides on how it's done, but essentially you just view the vector as a 4x1 matrix and do standard multiplication.[/QUOTE] I'm using GLM. I'll go look for a 'Transform' ability in the Vector class. I tried converting rotation on my own [img]http://i51.tinypic.com/wtsk7r.png[/img] That didn't go so well (White arrows represent bone orientations)
[QUOTE=Cuel;34666594]what are you trying to do? have the users only input digits?[/QUOTE] Exactly what I said, have the user input [i]up to[/i] four digits, without it requiring exactly four.
Having absolutely no luck with [url=http://code.google.com/p/berkelium-java/]berkelium-java[/url], nor the outdated jars, not the up to date subversion source. When attempting to run from jars, I add them to dependencies, and after modifying one of the examples so it runs under an older jar, it doesn't actually work as it should (AwtExample never paints a site) When attempting to run from source I get this: [code] initializing berkelium-java... Exception in thread "Berkelium Thread" java.lang.ExceptionInInitializerError at org.berkelium.java.impl.MultiThreadBerkelium.initThread(MultiThreadBerkelium.java:99) at org.berkelium.java.impl.MultiThreadBerkelium.access$200(MultiThreadBerkelium.java:13) at org.berkelium.java.impl.MultiThreadBerkelium$2.run(MultiThreadBerkelium.java:41) at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: org/berkelium/java/native/win32/icudt46.dll at org.berkelium.java.impl.NativeLibraryLoader.<init>(NativeLibraryLoader.java:73) at org.berkelium.java.impl.SingleThreadBerkelium.<clinit>(SingleThreadBerkelium.java:16) ... 4 more Caused by: java.io.FileNotFoundException: org/berkelium/java/native/win32/icudt46.dll at org.berkelium.java.impl.NativeLibraryLoader.open(NativeLibraryLoader.java:85) at org.berkelium.java.impl.NativeLibraryLoader.copy(NativeLibraryLoader.java:97) at org.berkelium.java.impl.NativeLibraryLoader.processFile(NativeLibraryLoader.java:121) at org.berkelium.java.impl.NativeLibraryLoader.loadLib(NativeLibraryLoader.java:79) at org.berkelium.java.impl.NativeLibraryLoader.<init>(NativeLibraryLoader.java:63) ... 5 more [/code] Has anyone had any success with berkelium-java? EDIT: So I edited it so it requires icudt42 rather than 46, because the version 42 is provider in the natives jar. Now I'm facing: [code]initializing berkelium-java... Exception in thread "Berkelium Thread" java.lang.UnsatisfiedLinkError: org.berkelium.java.impl.SingleThreadBerkelium._init(Ljava/lang/String;Ljava/lang/String;)V at org.berkelium.java.impl.SingleThreadBerkelium._init(Native Method) at org.berkelium.java.impl.SingleThreadBerkelium.<init>(SingleThreadBerkelium.java:21) at org.berkelium.java.impl.MultiThreadBerkelium.initThread(MultiThreadBerkelium.java:99) at org.berkelium.java.impl.MultiThreadBerkelium.access$200(MultiThreadBerkelium.java:13) at org.berkelium.java.impl.MultiThreadBerkelium$2.run(MultiThreadBerkelium.java:41) at java.lang.Thread.run(Thread.java:722) [/code]
I'm under the impression that I should be using revision control for bigger projects, but haven't the slightest idea what to use. Any suggestions?
[QUOTE=shill le 2nd;34661031][code]#include <stdio.h> #define NUMS 5 int calc(int in[], int out[]) { int i; int j; int out_i = 0; for (i = 0; i < NUMS; i++) { for (j = i+1; j < NUMS; j++) { if (abs(in[i] - in[j]) > 2) { if (out_i == 0 || i+1 != out[out_i-1]) { out[out_i] = i+1; out_i++; } j == NUMS; // go to next outer loop iteration } } } return out_i; } void print_array(int in[], int amt_nums) { int i; if (amt_nums == 0) { printf("nothing"); } else { printf("%d", in[0]); } for (i = 1; i < amt_nums; i++) { printf(", %d", in[i]); } printf("\n"); } int main(void) { { int nums[] = {1, 2, 2, 1, 3}; int out[NUMS] = {0}; int amt_nums = 0; amt_nums = calc(nums, out); print_array(out, amt_nums); } { int nums[] = {5, 2, 1, 1, 1}; int out[NUMS] = {0}; int amt_nums = 0; amt_nums = calc(nums, out); print_array(out, amt_nums); } { int nums[] = {5, 4, 1, 1, 1}; int out[NUMS] = {0}; int amt_nums = 0; amt_nums = calc(nums, out); print_array(out, amt_nums); } } [/code][/QUOTE] Thanks very much!
[QUOTE=chonks;34686941]I'm under the impression that I should be using revision control for bigger projects, but haven't the slightest idea what to use. Any suggestions?[/QUOTE] git
[QUOTE=chonks;34686941]I'm under the impression that I should be using revision control for bigger projects, but haven't the slightest idea what to use. Any suggestions?[/QUOTE] mercurial if you don't like git I use SVN because I was taught it in college but it's horrible, trust me
Git or Mercurial. Git is faster, Mercurial is.. ... Not Git?
Fixed my event problem. Now I got another one. The code below will be executed, by using this: [code] cNetwork net = new cNetwork(); net.Startlisten( "127.0.0.1", 8150 ); [/code] [code] public void StartListen( string cIP, int cPort ) { //------------------------------------- //Description: //Starts to listen on a certain IP and port //------------------------------------- try { IP = IPAddress.Parse( cIP ); listener = new TcpListener( IP, cPort ); Byte[] bytes = new Byte[256]; String cData = null; listener.Start(); while ( true ) { TcpClient cClient = listener.AcceptTcpClient(); //Connected! Console.WriteLine( "A client has connected!" ); cData = null; NetworkStream cStream = cClient.GetStream(); int I; while ( ( I = cStream.Read( bytes, 0, bytes.Length ) ) != 0 ) { cData = System.Text.Encoding.ASCII.GetString( bytes, 0, I ); Console.WriteLine( "Recieved: {0}", cData ); OnMessage( EventArgs.Empty, cData ); } cClient.Close(); } } catch ( Exception ex ) { Console.WriteLine( "Error: " + ex.Message ); } } [/code] the code works with the ip 127.0.0.1, but when I change the ip to something like 192.168.32.5 (ip exists in network), then I get this exeption: [B]Error: The requested address is not valid in its context[/B] [B]WHY?[/B]
you can't listen on someone else's ip address
[QUOTE=swift and shift;34691931]you can't listen on someone else's ip address[/QUOTE] Well... How would I go on listening for incoming TCP packets on a certain port?
[QUOTE=kaukassus;34692181]Well... How would I go on listening for incoming TCP packets on a certain port?[/QUOTE] new TcpListener(IPAddress.Any, 12345) iirc
[QUOTE=swift and shift;34692225]new TcpListener(IPAddress.Any, 12345) iirc[/QUOTE] I love you -fixed-
The address that you pass to the TcpListener constructor is the address that the connection is [i]to[/i], not [i]from[/i]. It has to be a valid address on the computer where the program is running. The reason why you can specify an address is because a computer can have more than one — think multiple network cards, for example — and you might need to have different programs handle connections on each. But most of the time you don't need to make that distinction, and you just want to listen for all connections to the computer (on a certain port) regardless of how many network cards or IPs it has, so you use IPAddress.Any.
[QUOTE=laharlsblade;34682718]Exactly what I said, have the user input [i]up to[/i] four digits, without it requiring exactly four.[/QUOTE] i've never used a MaskFormatter but i don't think that's what it is designed to do. you should try something else [editline]14th February 2012[/editline] perhaps a keypressed event handler and Character.IsDigit
I'm making a simple side-scrolling game similar to BIT.TRIP.RUNNER, where you basically have to jump on/over obstacles and survive as long as you can. I've been trying to think up a nice, neat and easy-to-use way of implementing the obstacle patterns for each level, but it's proving elusive. Has anyone done anything like this before, and wouldn't mind providing some insight for me?
Allthough slightly webdev its more a general programming problem, I have this java: [cpp]String charToCompare1 = Character.toString(passphrase.charAt(char1)); String charToCompare2 = Character.toString(passphrase.charAt(char2)); String charToCompare3 = Character.toString(passphrase.charAt(char3)); String input1 = (String)request.getParameter("passphraseinput1"); String input2 = (String)request.getParameter("passphraseinput2"); String input3 = (String)request.getParameter("passphraseinput3"); if(charToCompare1 == input1 && charToCompare2 == input2 && charToCompare3 == input3) { session.setAttribute("LoggedIn", true); response.sendRedirect("./index.jsp"); } else { out.print("<h4>Sorry wrong passphrase</h4>"); out.print(charToCompare1 + " = " + input1); out.print(charToCompare2 + " = " + input2); out.print(charToCompare3 + " = " + input3); }[/cpp] Which is always saying i got the wrong passphrase, but the debug print out prints this: Sorry wrong passphrase u = uw = wi = i there all the same, am i missing some weird java comparason thing here?
You can't compare strings with == in Java, use charToCompare1.equals(input1) instead. [URL]http://leepoint.net/notes-java/data/strings/12stringcomparison.html[/URL]
So I found a job on a freelancer site, Build a application that will send 10000s of emails , and save email adresses that reply. should automaticaly use proxys. is this legal for me to do?
[QUOTE=marcin1337;34711802]So I found a job on a freelancer site, Build a application that will send 10000s of emails , and save email adresses that reply. should automaticaly use proxys. is this legal for me to do?[/QUOTE] Well, Email spam is legal in the U.S. under the CAN-SPAM Act of 2003, as long as you follow certain "specifications". Personally, I don't know what this actually translates to, since I just found this out by looking it up on [URL="http://en.wikipedia.org/wiki/Spam_mail"]Wikipedia.[/URL]
Sorry, you need to Log In to post a reply to this thread.