Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Unimportant

Member
  • Content Count

    1,068
  • Joined

  • Last visited

Everything posted by Unimportant

  1. Unimportant

    Using laptop charger as power supply

    The overcurrent protection in a switching power supply is there to protect the power supply itself, not whatever it is powering. If you somehow bypass it and draw more current from the power supply then it's designed to handle it'll simply fail.
  2. Unimportant

    Multiple Questions, Stuck Here

    First, research how the compilation and linking process works. Once you've done that you can put yourself in the compiler's shoes. Each source file is compiled separately. So when main.c is compiled, it includes complex.h and the function prototypes therein. At no point in time will the compiler see the contents of complex.c while it's compiling main.c. Thus, you should define struct `complex` in the header file complex.h, so the compiler can see it when it's compiling main.c. There is also no need for the `input` char array to be in the struct. Furthermore, what is this doing in complex.h ? mag(complex a); phase(complex a); First of all, they don't have a return type, your compiler should warn for that. In modern C, the canonical way to write things is to explicitly write `void` as a return type when a function returns nothing. In this case, there are no functions `mag` and `phase` in complex.c so remove these prototypes to non-existing functions. Then, in complex.c: struct complex a,b,c; When you've typedef'd the struct there's no need for the struct keyword. These global variables are also never used and should be removed. complex getcomplex(char *input){ char input[20]; complex a,b; scanf("%s",&input); sscanf(input, "%lf+%lf", &real, &img); } The function `getcomplex` takes a string (pointer to char) as argument, presumably the string to be parsed? Why do you declare a new array, also called input and read user input with scanf? Also, there's only a single complex number to be parsed, so no need for a `a` and a `b`. You should explicitly point sscanf to the struct members. And you have to actually return the parsed complex. complex sum(double real, double img){ complex c;  c.real = a.real + b.real; c.img = a.img + b.img;  printf("Hasil operasi penjumlahan bilangan kompleks = %d + %di", c.real, c.img); return (c);  } This function is supposed to sum 2 complex numbers `a` and `b`. Why does it take 2 doubles `real` and `im` as arguments? The printf specifier to print doubles is `%lf`, not `%d`. Similar problems plague the other functions in complex.c In main.c char ch,p,q,r; p = argv[1]; q = argv[2]; r = argv[3]; `argv` is a array of pointers to char, not char. switch(ch){ case 'sum': sum(getcomplex(q),getcomplex(r)); break; case 'substract': substract(getcomplexA(q),getcomplexB(r)); break; case 'multiply': multiply(getcomplexA(q),getcomplexB(r)); break; case 'divide': divide(getcomplexA(q),getcomplexB(r)); break; } You cannot switch on an entire string. Comparing strings has to be done with a function like `strcmp`. Also, strings require double quotes. Final modified program, complex.h: #ifndef COMPLEX_H_INCLUDED #define COMPLEX_H_INCLUDED typedef struct { double real; double img; } complex; complex getcomplex(const char *input); complex sum(complex a, complex b); complex subtract(complex a, complex b); complex multiply(complex a, complex b); #endif // COMPLEX_H_INCLUDED complex.c: #include <stdio.h> #include "complex.h" complex getcomplex(const char *input) { complex a; sscanf(input, "%lf+%lf", &a.real, &a.img); return a; } complex sum(complex a, complex b) { complex c; c.real = a.real + b.real; c.img = a.img + b.img; printf("Hasil operasi penjumlahan bilangan kompleks = %lf + %lfi\n", c.real, c.img); return c; } complex subtract(complex a, complex b) { complex c; c.real = a.real - b.real; c.img = a.img - b.img; printf("Hasil operasi pengurangan bilangan kompleks = %lf - %lfi\n", c.real, c.img); return c; } complex multiply(complex a, complex b) { complex c; c.real = a.real*b.real - a.img*b.img; c.img = a.img*b.real + a.real*b.img; printf("Hasil operasi perkalian bilangan kompleks = %lf + %lfi\n", c.real, c.img); return c; } main.c: #include <stdio.h> #include <string.h> #include "complex.h" int main(int argc, char *argv[]) { if (argc < 4 || argc > 5) { printf("Tolong masukan minimal 4 argumen. //ex. namafile arg1 arg2\n"); return 0; } const char operator = argv[1][0]; const char* q = argv[2]; const char* r = argv[3]; switch(operator) { case '+': sum(getcomplex(q),getcomplex(r)); break; case '-': subtract(getcomplex(q),getcomplex(r)); break; case 'x': multiply(getcomplex(q),getcomplex(r)); break; } } The `divide` function was removed and implementing it is left as an exercise. Example command line: ./test_complex + 5+3i 7+2i output: Hasil operasi penjumlahan bilangan kompleks = 12.000000 + 5.000000i
  3. Unimportant

    Lock an app with an app :DD

    One could write a program that encrypts other program's executable files and requires a correct password to decrypt and run the encrypted program. That sounds a lot like ransomware tough, thread lightly.
  4. Unimportant

    Extract Two Float/Double Numbers Out of a String on C?

    #include <stdio.h> int main(void) { const char* exampleString = "-2.2+3i"; double real; double im; if (sscanf(exampleString, "%*[^0123456789]%lf%*[^0123456789]%lf", &real, &im) != 2) { printf("Failed to extract real & im!\n"); return 1; } printf("real: %lf, im: %lf\n", real, im); return 0; }
  5. Unimportant

    What Component is This?

    Looks like 0805.
  6. Unimportant

    Most imporant things a audio engineer should know

    You have to be more specific, what field of audio engineering ?
  7. Unimportant

    What Component is This?

    Looks like a burned SMD resistor (#). The resistor to the right of the circled resistor, under the SOT23 device is in the same circuit and looks burned aswell. Measure the SOT23 device for resistance. it's probably shorted all way 'round. #: The black part of a SMD resistor is the actual resistive material. If it gets burned away the white ceramic carrier comes trough. The scribbles that remain in the middle would've been the ink of the value markings. https://www.electronics-notes.com/images/smd-surface-mount-resistor-construction-cross-section-01.svg
  8. Unimportant

    RAM speed in programming

    While you indeed should not be optimizing too much prematurely, *some* hardware behavior should be kept in mind from the very beginning as it can have a great influence on the overall design. We had a multi-threaded application run glacially slow once, as it turned out due to false sharing. To solve the false sharing issue certain parts of the application's data structure had to be modified. What is the data structure in OOP ? Your object structure. So we had to radically change part of the object structure which, as you're probably well aware, took a lot of refactoring and time (money). When certain decisions have to be right from the very beginning, because they're too costly too change afterward, then thinking about and making the right decisions from the start isn't premature. The hardware, mostly caching, affects certain such decisions.
  9. Unimportant

    C++ programmers please help

    The index operator [] already dereferences the indexed element. Dereferencing it again results in the error. if(scores[k] > scores[k+1]) You can also do arithmetic directly on pointers. So if you need a pointer there is no need to use index operator [] to dereference a index and then take it's address again. swap(scores + k, scores + k + 1); Although you should be using std::swap instead of rolling your own unless there's a good reason for it.
  10. Unimportant

    RAM speed in programming

    Afaik DRAM is still is orders of magnitude cheaper then SRAM. Look at the amount of die space a handfull of megabytes L3 cache takes. (Source: Random anandtech article pulled from google. ) Imagine what a couple gigabytes would look like and cost. Edit: I also see no technical reason why we would be "stuck" with anything. If cheap SRAM technology were to be invented, there's nothing to stop Intel/AMD from releasing new CPU's/chipsets that would use SRAM memory sticks totally transparant to the software.
  11. Unimportant

    C++ | Can't understand Polymorphism

    Forgive me for thinking these were 2 completely different things: ((Entity*)&hero)->set_attack(5); Entity(hero).set_attack(5); I know better now. Although my compiler produces 2 completely different results. I guess I should compile without the -pedantic flag.
  12. Unimportant

    C++ | Can't understand Polymorphism

    Not sure why you took this so offensively but no ill intent.
  13. Unimportant

    C++ | Can't understand Polymorphism

    I'm sure you're well aware that casting is a explicit type conversion. In the examples given, no type conversions are made. All they do is refer to a class instance trough a base class pointer. I'm just a bit worried the OP might go and look up "casting" and get even more confused. I've learned to be careful with the terminology among "students".
  14. Unimportant

    C++ | Can't understand Polymorphism

    Be careful with the terminology, there hasn't been a single cast in this whole thread.
  15. Unimportant

    RAM speed in programming

    I'd worry much more about being cache friendly if you need performance.
  16. Unimportant

    How do parallel battery packs not have issues?

    Rather importantly, yes! When you connect the batteries together to make a pack they should be balanced. If you put 2 batteries with different charge levels (different voltages) in parallel the 2 batteries will balance themselves, but with no current limit, it would be violent. Once connected in parallel there is no issue - look at them as communicating water vessels.
  17. Unimportant

    Operating System Creation

    And even then you'd need to write bits in assembly to do the low level management a OS needs to do. On x86 you need to manage the GDT, for example, there are no C equivalents for the LGDT, LIDT, LTR, etc instructions. On ARM there's no C equivalent for ERET, etc...
  18. Unimportant

    Operating System Creation

    That's what AT&T syntax will do to a person. ( )
  19. Unimportant

    I'm going to start a project

    18W RMS is the max. possible with a 12V supply and a 4 ohm load with push-pull as I've already said multiple times. So if Kenwood, JBL, Sony, Alpine, etc output 4 push-pull channels (simplified: 8 channels internally bridged to 4 outputs) then yes, they can do 4x 18W RMS. However, you can't bridge them again after that. You can't "bridge a bridge". 18W RMS is the end station without boosting voltage. Most head units have claims of 4x50W or even higher ridiculous numbers written on their front. Those are useless peak values that can be massaged any way they like. Since the OP says he's going to bridge his outputs that implies his head unit has single ended outputs, otherwise you would not be able to bridge them externally. So he has max. 4.5W RMS per single ended output and if he bridges 2 outputs he's got max 18W RMS. That's a far cry from the 120 Watt per channel the OP was hoping for in an earlier post - That is all I'm pointing out. But again, 18W RMS can be plenty loud.
  20. Should work with Rufus, follow this simple guide https://www.thomas-krenn.com/en/wiki/Creating_a_Bootable_DOS_USB_Stick Make sure all the settings are the same. You need FAT32 for example as DOS does not know NTFS.
  21. Unimportant

    Why do we count Cores the way we do?

    Computers work with bits, which can be either off/0 or on/1. Any larger number is just a combination of multiple bits. All bits off equals zero and is a valid state, why waste a valid state ?
  22. The Netherlands was PAL, yes. But France was SECAM so you can't make blanket statements about the EU.
  23. Unimportant

    I'm going to start a project

    That JL300/2 is a standalone amplifier, most of those indeed have the necessary voltage booster on board to deliver the claimed wattages. However; we're talking about a plain head-unit here, and a cheap one at that. I have never *EVER* seen a headunit with a voltage booster on board for the amp in over 40 years, not even the expensive ones. Without it, the best you can muster is 4.5W RMS single channel or 18W RMS bridged on a 4 ohm speaker with a 12V supply, that's just math. Class D or not does nothing to help in this respect. So the numbers on all those headunits are meaningless peak values or just lies. Now, that does not mean it won't be loud. The problem is audio amplifier output numbers have been exaggerated for so long (I remember tiny PC speaker sets which claimed 300W P.M.P.O - Where P.M.P.O is yet another bullshit metric - they were really 1W RMS) that most people can't imagine how loud a few real RMS watt's can be (very). But that is another issue.
  24. Unimportant

    I'm going to start a project

    Audio is always AC. The + and - are simply designations to make sure you connect all your speakers in phase. If you were to connect speakers in anti-phase 1 speaker would be "pushing" while the other is "pulling" and vice versa. Their audio waves would (partly) cancel each other out and that sounds bad.
  25. Unimportant

    Operating System Creation

    To write a OS you will need decent knowledge of how to manipulate the hardware yourself. Making BIOS calls, configuring things trough CPU IO ports, installing interrupt handlers, etc... To learn these things I'd suggest you start off "simple". Download and install Open Watcom C++, which is a project that maintains Watcom C++, once the de facto standard C/C++ compiler for DOS. It also includes the Watcom assembler. Then install Dosbox. The goal is to use Watcom C++, installed and running in windows, to build DOS applications which you can then run in Dosbox. DOS allowed straight access to the hardware, so you can play around and try things without all the protections and safeguards of a modern OS. By running your test applications in the Dosbox emulator rather then on real hardware it's completely safe. You're not actually working with the real hardware, just the dosbox emulation - The worst that can happen is you crash Dosbox. Try to switch to videomode 13h (320*200*256), (int 10h BIOS call). Try to plot pixels by directly accessing video memory (A0000h). Try configuring the VGA controller's color palette trough it's IO ports. If you think you're ready, try soundblaster DMA playback, which involves asking DOS (int 21h) for a block of real mode memory, configuring the DMA controller, installing a interrupt handler and configuring the soundblaster. The documentation for all this is freely available out there online - finding it, understanding it and applying it are part of the exercise. Those are "simple" first baby steps that are probably enough to get you going for a while. That'll either prepare you for the next steps or put you off for good - try and see
×