Jump to content

Delay

Members
  • Posts

    1,246
  • Joined

  • Last visited

Everything posted by Delay

  1. @Green BaronI now have the book. It is the variant on C99, not C11, but aside from texts being written like {" "} in the book, there doesn't seem to be any absolutely massive difference between the two that would make the book utterly useless. Even after looking it up it seems like the changes are smaller ones and not absolute game changers. Skimmed through the Array chapter, most importantly string handling. There were some things in there that I didn't think of before, like simply testing until "\0" occurs in for loops. And I think I now (sort of) understand why strcat() doesn't work when adding an indexed character to a char array. (I'll pretend they are strings for simplicity). What I think is happening is that the character resulting from an index is not a string, but instead just one character. Since strcat() combines two strings, not strings and chars, I'd get an error for attempting so.
  2. Delay

    Primes

    According to my little Python script (cheating?), the next prime after 179 is: 181.
  3. I doubt that. It really seems like he knows what he's talking about. In fact, I don't want what you said to be true. I want him to have come up with it himself.
  4. I love my teacher so much. I open up the file and modify it slightly, according to the results here. Lo and behold, I get bombarded with errors nonetheless. Now; As a teacher, seeing one of the few students who genuinely try to work, do you: A) Help the student? B) Ignore the student? C) Rather talk and listen to someone who clearly doesn't have any problems with the task and is instead merely boasting about how they already managed to use DirectX to display a cube? As a responsible teacher he of course knew what answer was the correct one. C, of course. Don't get me wrong: Good for the other student. It's impressive that he's already able to use a 3D engine to display something, and that's not even sarcastic. I'm genuinely congratulating him here. However, of course I do start wondering why he even is in the class if our Einstein already knows everything anyone ever needs to know about computing, or at the very least why he doesn't help anyone. Other than his friends, of course. Those are privileged. In the end the teacher actually did manage to fix my error. Not by explaining why it works now and not with my original concept. The response to my question of "Shouldn't this (his solution) leak?", with my - and keep this in mind - very limited knowledge and my tendency to severely overextrapolate, was - how could it be anything else - technobabble no one outside of him and Einstein over here could ever understand.
  5. Can anyone confirm that there are no Pythagorean triples where one of the legs is equal to half the hypotenuse? Because if that's correct I accidentally just proved that.
  6. Well, I don't! But I agree. It sounds fantastic! You can make millions!
  7. @Green Baron 2 problems with getting a book. 1. It's 10:22 PM. No store is opened anymore. 2. Tomorrow is Sunday, when all stores are closed for the entire day. The next time stores are open is Monday, and that's when I have the next CS class. Usually it's Tuesday, but this week it got shifted to Monday. (Now's the perfect time to play a soundclip of a crying baby) Since yesterday I learned pretty much nothing other than what it feels like to be really frustrated because the complexity of a topic just shot up to infinity. It all seems like Monday's class will be an utter waste with 67 1/2 minutes of nothing productive happening. Am I just dumb or is programming in C really as difficult as I think it is?
  8. that doesn't make things better, it just shows it could be worse. The only exposure I had to Assembly as of now is - strangely enough - arbitrary code execution on the Super Nintendo, or rather explanations of why and how they work. Didn't understand a thing. (But it was still informative and interesting)
  9. Haha, Arduinos don't work with Python. Believe me; if they did I this 4-page thread wouldn't exist at all and I'd already be done. Nothing to see here; move on to more productive things. Instead I'm forced to torment myself, tasked with the impossible of "learn the basics behind how a computer works, how to allocate memory and overcome problems that shouldn't even be problems in 2 days!". I literally only have this weekend until the next CS lesson on Monday, and I don't want to waste that.
  10. My head hurts. What does C have against using strings? No, I have to compare every single member with every single other member? Individually? I don't see how that is supposed to make sense. In any context. When would you not want to be able to compare strings directly? What if, instead of using dot, dash, etc, I simply use ints 0, 1, 2, 3 and explain what they represent in comments next to it? That's a lot faster, both for me and the program (though for the latter it's pretty much a meaningless change).
  11. Well, I didn't come up with that switch-statement, my unimaginably limited knowledge of C syntax (as I make a good job of showing that) didn't include this. I will happily take the credit, though, so thanks I guess? @Green Baron, so if I understood correctly, my cases in the switch shouldn't work, since "case 'dot': " is not one single character. So I guess I'll have to use ifs? "if(signal == 'dot')", maybe? As for memory and storing things correctly - I don't want to pick up bad habits after all and fill up memory, though that would be quite fun - , you'll have to start at the very beginning. I have no idea what pointers are; heck, I don't even know how a computer stores things at all. Remember that I've never been given any clear explanation of how C works, much less how a computer does. What I've shown in this thread is based on the assumption that some things in C are similar to Python in some way, hence "Text = Text + Something", which I now know is nonsense. And despite this, my own code is the minority of what I present. Most of this is coming from this very forum, modified slightly to fit into the project.
  12. Since it shows Google results when it decides to actually do what I want it to do: Does Google even work correctly when you use quotation marks?
  13. Firefox really like to interpret search queries as URLs. So I'm typing in "string.h" and it tries a URL, rather than just listing the Google results. And there doesn't seem to be an option to turn that off.
  14. Here it is: #include <string.h> int LED = 10; char Text[] = "Hello World!"; int dotTime = 250; //in ms /* Signal types: */ void send_start(){ digitalWrite(LED, HIGH); delay(4 * dotTime); digitalWrite(LED, LOW); delay(4 * dotTime); } void send_dot(){ digitalWrite(LED, HIGH); delay(dotTime); digitalWrite(LED, LOW); delay(dotTime); } void send_dash(){ digitalWrite(LED, HIGH); delay(3 * dotTime); digitalWrite(LED, LOW); delay(dotTime); } void send_space(){ delay(2 * dotTime); //1 unit + 2 units = 3 units } void send_wordspace(){ delay(6 * dotTime); //1 unit + 6 units = 7 units } void send_end(){ digitalWrite(LED, HIGH); delay(5 * dotTime); digitalWrite(LED, LOW); delay(5 * dotTime); } /* letter -> Morse code: */ char MorseCoder(char in_char){ switch(in_char){ case ' ': send_wordspace(); break; case 'A': //A: KL case 'a': send_dot(); send_dash(); send_space(); break; case 'B': //B: LKKK case 'b': send_dash(); send_dot(); send_dot(); send_dot(); send_space(); break; case 'C': //C: LKLK case 'c': send_dash(); send_dot(); send_dash(); send_dot(); send_space(); break; case 'D': //D: LKK case 'd': send_dash(); send_dot(); send_dot(); send_space(); break; case 'E': //E: K case 'e': send_dot(); send_space(); break; case 'F': //F: KKLK case 'f': send_dot(); send_dot(); send_dash(); send_dot(); send_space(); break; case 'G': //G: LLK case 'g': send_dash(); send_dash(); send_dot(); send_space(); break; case 'H': //H: KKKK case 'h': send_dot(); send_dot(); send_dot(); send_dot(); send_space(); break; case 'I': //I: KK case 'i': send_dot(); send_dot(); send_space(); break; case 'J': //J: KLLL case 'j': send_dot(); send_dash(); send_dash(); send_dash(); send_space(); break; case 'K': //K: LKL case 'k': send_dash(); send_dot(); send_dash(); send_space(); break; case 'L': //L: KLKK case 'l': send_dot(); send_dash(); send_dot(); send_dot(); send_space(); break; case 'M': //M: LL case 'm': send_dash(); send_dash(); send_space(); break; case 'N': //N: LK case 'n': send_dash(); send_dot(); send_space(); break; case 'O': //O: LLL case 'o': send_dash(); send_dash(); send_dash(); send_space(); break; case 'P': //P: KLLK case 'p': send_dot(); send_dash(); send_dash(); send_dot(); send_space(); break; case 'Q': //Q: LLKL case 'q': send_dash(); send_dash(); send_dot(); send_dash(); send_space(); break; case 'R': //R: KLK case 'r': send_dot(); send_dash(); send_dot(); send_space(); break; case 'S': //S: KKK case 's': send_dot(); send_dot(); send_dot(); send_space(); break; case 'T': //T: L case 't': send_dash(); send_space(); break; case 'U': //U: KKL case 'u': send_dot(); send_dot(); send_dash(); send_space(); break; case 'V': //V: KKKL case 'v': send_dot(); send_dot(); send_dot(); send_dash(); send_space(); break; case 'W': //W: KLL case 'w': send_dot(); send_dash(); send_dash(); send_space(); break; case 'X': //X: LKKL case 'x': send_dash(); send_dot(); send_dot(); send_dash(); send_space(); break; case 'Y': //Y: LKLL case 'y': send_dash(); send_dot(); send_dash(); send_dash(); send_space(); break; case 'Z': //Z: LLKK case 'z': send_dash(); send_dash(); send_dot(); send_dot(); send_space(); break; default: send_space(); } } void setup() { pinMode(LED, OUTPUT); } void loop() { send_start(); for (int i=0; i < strlen(Text); i++){ MorseCoder(Text[i]); } send_end(); delay(2000); } Pretty sure that "MorseCoder" could actually be void, since it doesn't return anything. It takes input, does somethings, execution goes back to the loop and repeats it. Nothing returned as far as I can see.
  15. @IncongruousGoat This makes me question my script for sending the Morse code. I'm now slightly worried that I did this somewhere or similar beginner's mistakes before. Should I post the complete script? Don't see this as "correcting someone's work because they're too dumb" or something. See it as an opportunity for me to learn from my mistakes by drawing attention to them. Though your head will probably explode in the process of making the list. Or you run out of papers. Or hard-drive space. Whatever comes first.
  16. Wait, so you can't actually overwrite a string with nothing? Since you can "=" it to something? (Not that that'd help, I just want an option to reset the string here)
  17. I think I'm beginning to see why @IncongruousGoat doesn't like Python. It's taking off way too much work. First the variable and function declarations. Then string concatenation. Now it's memory that I additionally have to worry about.
  18. Yes, though for some reason I like to give things english names. Thanks, I'll take a look at it.
  19. Thanks, but I don't get why the compiler only flags an error for the last one. The correlation with index = 0 might've been a little far-fetched (I was just going off some assumptions and the differences in the lines), but why does it "wait" until the last occasion to tell me that there are some fundamental things wrong? As for my teacher... Not sure if this begs the questions of how he even managed to get into teaching CS, I started questioning that since the moment he simply threw us into C without a warning. We were doing some basic theory before that... how computers store things, ASCII, two's complement. Suddenly: Arduino.
  20. I have a book on C++... So close! I was going for a function call. Just realized that you don't need { and } then. If a function requires an argument to work, the name for its argument(s) can still be arbitrarily assigned. For the function declaration I could use "function_argument", but call it with "output" to be used as "function_argument". Anyways, there's something that I really don't understand, not even my teacher could figure out what was wrong in the limited amount of time left. char Text[] = ""; char CharacterTree[] = " etianmsurwdkgohuf-l-pjbxcyzq--"; int index = 0; int dotTime = 0; //(plan here is to make the transmission rate completely up to the transmitter) int Input = A0; //photosensor stuff int sensorWert = 0; //above char Tree(char input){ switch(input){ case 'dot': index = 2 * index + 1; break; case 'dash': index = 2 * index + 2; break; case 'space': Text = Text + CharacterTree[index]; //this line works just fine index = 0; break; case 'long_space': Text = Text + CharacterTree[index]; //this line also works index = 0; Text = Text + CharacterTree[index]; //Problematic line break; } } void setup() { Serial.begin(9600); //just some setup according to a website with Arduino coding examples (most importantly a photosensor) } void loop() { sensorWert = analogRead(Input); //refer to above. setup and loop are so far only testing the sensor and shouldn't be relevant here. Serial.println(sensorWert); } The marked line is supposed to add a character to the string "Text". For this particular line, "index" is equal to 0, which would be space. However, instead of doing that it throws an error back at me. I can't remember its content, but looking it up it probably was "invalid conversion from 'const char*' to 'char' " or something similar. What I don't get is that this is the only line to cause this problem. Especially since there are two very similar lines above this one, and it reads these just fine. The only difference between them is this is the only line to refer to CharacterTree[0], but that should be a valid index. Or is " " different? What's wrong here? Indices start at 0, right?
  21. Does every single word or variable have to be declared as a char or int or what have you? In my case, would it be enough to say "Function(argument){}" or do I have to say "Function(char argument){}"?
  22. To your dad's dismay or is he joining in on the fun?
×
×
  • Create New...