Jump to content

MikeD

Member
  • Posts

    216
  • Joined

  • Last visited

Everything posted by MikeD

  1. Here is something for the C++ template lovers, featuring macros! #include <iostream>using namespace std;template<char C>void print();#define PRINT(I,C) \ template<> \ void print<I>() { \ cout << C; \ }#define FOREACH(MACRO) \ MACRO(0, 'H') \ MACRO(1, 'e') \ MACRO(2, 'l') \ MACRO(3, 'l') \ MACRO(4, 'o') \ MACRO(5, ' ') \ MACRO(6, 'W') \ MACRO(7, 'o') \ MACRO(8, 'r') \ MACRO(9, 'l') \ MACRO(10, 'd') \ MACRO(11, '!')FOREACH(PRINT)template<int I = 0>struct MetaPrinter { static void next() { print<I>(); MetaPrinter<(int)I+1>::next(); }};template<>struct MetaPrinter<12> { static void next() { cout << endl; }};int main() { MetaPrinter<0>::next(); return 0;} It might not be very elaborate, illegible or time-consuming, but it's definitely useless!
  2. If you're using Putty you can pair it with WinSCP to be able to browse the server file structure and to open and edit files. I still like Vi better! You are welcome! I'm just glad to be of assistance!
  3. How are you connecting? Through SSH? If so you can open the code in Vi on the terminal and copy from there (I don't think you can copy everything at once though!) or try to forward the graphical server and open gedit from the server (if it is allowed). Anyways, that error might be if you use scanf of a char like scanf("%c", end). Scanf expects a pointer as the second argument so you must do scanf("%c", &end), like I did above. Edit: As they are chars, in the ifs you must compare (end != 'c') instead of (end != "n"), because 'n' is a char and "n" is a string.
  4. end and endShuffle should not be arrays since they are only one char. And even if they are arrays you cannot access position 1 when the array only has 1 position because they start at 0. With this code it works for me: #include <stdio.h>#include <stdlib.h>#include <string.h>int main() { int i, j; char string[81], end = 'y', endShuffle = 'y', temp; srand(0); while(end != 'n') { endShuffle = 'y'; printf("Please enter a string with 10-80 characters:\n"); scanf(" %s", string); printf("Original string: %s\n", string); while(endShuffle != 'n') { for(i = strlen(string) - 1; i >= 1; i--) { j = (int) rand() % i; temp = string[i]; string[i] = string[j]; string[j] = temp; } printf("New string: %s\n", string); printf("Would you like to shuffle this string again? "); scanf(" %c", &endShuffle); } printf("Would you like to shuffle another string? "); scanf(" %c", &end); } return 0;} PS: Please, next time use the code tag (<> in the editor) to make it easier for everyone, even if you want to put an image of the error or something else
  5. There are custom graphics drivers, in Linux for instance. @sTizzl You can create your own drivers, but it's not easy at all. You have to know how to build/compile drivers for your architecture/OS and, more importantly, reverse engineer the communication protocol for your card. But I'm not sure you can boost whatever with the drivers. Maybe changing the firmware on the card, but that's a whole other subject, possibly even more complicated than the drivers and probably impossible.
  6. I know assembly in general, not this one in specific, but I'd say that the error is in swap, when you load address 0 to $a0 instead of Array. When you jump back to loop you try to access address 0. This is assuming everything else works as I think it does! I might be completely wrong though, I haven't messed with assembly like that in a while. Also, where is the loop/main termination? I don't think you can go on forever!
  7. in fscanf, the format argument (second argument) is just one string, no opening and closing " in the middle. And to read strings you use %s, not %c (which will only read one char). It would be something like status = fscanf_s(in,"%s %d %s %d %s %d %s %d %s", event_name[i].name, event_name[i].place1, event_name[i].nation1, event_name[i].place2, event_name[i].nation2, event_name[i].place3, event_name[i].nation3, event_name[i].place4, event_name[i].nation4);
  8. That's because you are creating a new object every time you call main. And this is because you are still using recursion. If you do some restructuring, like @WanderingFool said earlier the problem will disappear. Something like this: import java.io.*;public class Calculate { BufferedReader scan = new BufferedReader(new InputStreamReader(System.in)); State stateObject = new State(); End endObject = new End(); public void calculate() throws IOException { double num1=0, num2=0, answer=0; String operate; stateObject.statement(); try { Thread.sleep(500); } catch (InterruptedException e){ } System.out.println("Please select your operator"); operate = scan.readLine(); System.out.println("Enter first value"); num1 = Double.parseDouble(scan.readLine()); System.out.println("Enter second value"); num2 = Double.parseDouble(scan.readLine()); if (operate.equals ("+")) answer = num1 + num2; if (operate.equals("-")) answer = num1 - num2; if (operate.equals ("*")) answer = num1 * num2; if (operate.equals ("/")) answer = num1 / num2; System.out.println("Your answer is..."); System.out.println(answer); try { Thread.sleep(1000); } catch (InterruptedException e){ } } public boolean wantsToContinue() throws IOException { System.out.println("Would you like to clear?"); System.out.println("Type yes or no."); String s = scan.readLine(); if (s.contains("yes")) { return true; } if (s.contains("no")) { return endObject.finalmessage(); } return false; } public static void main(String[] args) { Calculate calc = new Calculate(); try { do { calc.calculate(); } while (calc.wantsToContinue()); } catch (IOException e) { System.out.println("Something went wrong reading input."); } } } import java.io.*;public class End { BufferedReader scan = new BufferedReader(new InputStreamReader(System.in)); public boolean finalmessage() throws IOException { System.out.println("Bye"); System.out.println("Type 'on' to restart"); String sentence = scan.readLine(); if (sentence.contains("on")) return true; else return false; }} public class State { int runs = 0; public void statement(){ if (runs == 0) System.out.println("This program is a simple calculator"); if (runs < 0) System.out.println(" "); runs = 1; }} Note that: 1) I had to change the input method because the scanner was having trouble sometimes. The disadvantage is having to handle IOException but, since I have other things to do I handled it as late as possible (in the main); 2) I simplified a few things that were unnecessary; 3) This could be further simplified (you only need one class really) but I kept the three to show you that now num is not "reset"
  9. public class Foo { int num = 0; ... public void statement() { if(num == 0) { System.out.println("..."); num = 1; } }} I'm not sure this is what you're trying to do though.
  10. I'm guessing what you want to do is remember that you have already displayed the message... You could make num be an object variable. That way, each time the method is called in that instance the value is the same.
  11. Welcome to the Internet! While you are on the SQL Injection train, which, by the way, can be solved with stored procedures and input sanitation, you might want to look at Cross Site Scripting, PHP file/shell/eval injection or overflows (stack smashing, heap/BSS overflow, index overflow, format overflow) in, for instance, CGI scripts (or any C program). And then you can move on to covert channels, sniffers, ARP spoofing, MAC flooding, IP spoofing, TCP hijacking, SYN flooding, ICMP "SMURF", DoS with Chargen and Echo, ping-of-death, teardrop attack, land attack, the Kasminsky DNS attack. And then you can move on to flaws in encryption or hashing mechanisms (replay attacks, sign and cipher order that can lead to message stealing, key management and distribution, granting perfect forward secrecy), weaknesses in authentication mechanisms or wireless protocols, ... The world of computer and network security is huge, and there are new vulnerabilities being discovered at the same pace, or even faster, than new security technologies are coming out. That's one of the reasons why it's not sufficient to have programming (read coding) skills, you need to know much more than a couple of languages to be able to develop a secure piece of software and make it available to the world via the internet.
  12. I imagine you are getting the error after the if blocks. Unlike some languages (Python is an example I believe) C# variables are scoped. If you define, like you are doing, a variable inside the if block it will not be visible outside. You have to declare the variable outside and assign it in the ifs. You are probably going to have to use a supertype of the monster instances you are creating and assigning the actual monster to it.
  13. Note that there is no limit to how many chained elifs you can have.
  14. Headers do not include c files, only the other way around. And a module is usually a group of source files or it can be just one. They are not, however, parts of a file (it seems you are considering that the file main.c has several modules). In the simplest case where each file is a module there is one header per c file, the c file includes the header and headers can include other headers. Although, in a simple case, you wouldn't need to include headers in each other (it could lead to recursive dependencies and your program wouldn't even compile unless you take extra care to avoid that). At the end there would be a program that uses the modules (i.e. main.c) and the file would include the headers and the code that uses those functions.
  15. Basic (you should really know these): HTML, CSS Intermediate (for more dynamic pages and websites): PHP, SQL, Javascript, Ajax (is this still used?) Advanced: Django web framework, GWT (for browser applications), etc.
  16. Yes, the if statement is more adequate, since you want to perform an action depending on the operator and not keep performing it while the operator is that one. Instead of using recursion you could have a while cycle that checked a variable (boolean, for instance) and, while that variable is true you'd perform the reads and operations. At the end, in your if(sentence.contains("no")) you'd set that variable to false to end the cycle.
  17. 1st: please use the code tags (symbol <> in the editor) 2nd: Are you sure you want to use whiles in the operations? (Rhetorical; you do not!) 3rd: main recursion?! No. 4th: No need for different scanners.
  18. It depends on the architecture of the system and it's function. You should divide your system in modules at the right granularity: not too general (a module that does almost everything) but not too small (a different module for each step in a chain). If your system has many different types of input, process and output mechanics that can be used interchangeably, maybe. But if those are steps in a process that occur one after the other and the other components of the system will only provide input at the beginning and then collect a result at the end I'd say all those things belong in the same module. You do not have to place all function prototypes. Only the ones that will be used by the rest of the system. You shouldn't include any local helper functions because those are a part of the module and not meant to be used independently (if you want to count apples from an input that also has bananas you'd declare the function count but you wouldn't declare the function is_banana because the latter is only supposed to be used by the former). And yes, the prototype is something like 'int count(Basket basket_of_fruits)' You include the header files wherever you need to use the functions it declares and in the corresponding .c file. If the file where you declare the main does not need those functions, do not include it there. And each module should have only one header file, unless you want to define different interfaces to different parts of the system, but generally you shouldn't do this. You have to be very careful with constants: do not define the same constant in multiple places of the code. If it's something that the users of the module need to know then I'd say yes. If you do not understand structures and typedef'ing I would study that first. What that paragraph is saying is that you should not define structures in header files. Only typedef the structure so that the clients can use it. But, like I said, unless you have documentation on how to use the structure elsewhere the clients still can't use it because they do not know the internal structure.
  19. In a header file you usually find function or structure declarations associated with the respective .c file or that serve as an interface to other projects. For instance, say you have a bunch of different ways to do some work (count fruits) and a bunch of things you want to test those ideas with (bananas and apples). Since the behavior of the counting is the same you'll probably end up with a bunch of files with a function with the same name that receives the same inputs and returns the same outputs. One way to organize this is to create a framework where all implementations of those ideas (how to count fruits) live and that include the same header file. Then, your tests can use that simple interface to do the counting with a chosen method without seeing any of the internal details. One thing that I do not completely agree with in that article is the "DON'T expose the internal format of any module-specific data structure passed to or returned from one or more of the module's interface functions.". If you only typedef the structure other people may use it but they won't know how to use it unless they have documentation about it elsewhere (they know the type exists but not what fields it has). And sometimes you may have to declare variables defined in base files, but usually you won't need to do this unless you are working on a complex system and have no other way of doing it.
  20. I'm not falling for that faith in humanity thing again. When I want to feel less depressed I'll just look for cute cat pictures on the web!
  21. The portal juice, the #cake, the Steam Controller or everything in general in this thread?!
  22. Well, I'm just glad that someone also sees the cake! It came out a bit deformed, when it was baking it looked less... spacey! And "hashtag"cake may very well be the first e-delicacy!
  23. You know what else is fake/a lie?! \ / (##) |#########| |#########| |#########| This is a cake! With cherry on top. And yet, science happens!
  24. MikeD

    SteamBox Beta

    Not me, I don't have the time it would require.
×