![]() |
![]() |
#1 |
Feb 2013
22×7 Posts |
![]()
Hi all, I'm having issues. I'm not "new" to C, but I've never practiced it or build great big things with it either. (I supposed I might as well be a noob, oh well.)
Down here I'm having trouble doing simple subtraction and that is annoying to me. It's on the powerM variable. It prints eff the value 21 for 83 - 21. I'm just noobily speculating that maybe the print eff is on the fritz and that the real value plugs correctly through the rest of the function. In that case there is something else wrong with my program, in addition to the print eff, because my final product is wrong by one digit. (>.>) 'Case you're wondering, I'm building a manual square rooting program. ->> Some of those other variables were just things I made up to check what's wrong..."sub"ing in variables for direct digital numbers. I've made a bit of a mess. thanks Code:
int finish_root(int U,int P) { unsigned int place = (U%10)*2; place = (place + (U - U%10))*10; unsigned int powerM; unsigned int y=0; unsigned int S=0; unsigned int Remainder; //unsigned int save = D; //unsigned int sub = U*U; powerM = 83-81; printf("%u",powerM); for (y = 0; S==0; y++) { if (((place + y) * y) > ((powerM*100) + P)) { if (((place + (y-1)) * (y-1)) != ((powerM*100) + P)) { y = y - 1; } printf("%u\n",y); Remainder = (powerM*100 + P) - ((place+y)*y); S = 1; } } DENOM = place+y; printf("%u\n",DENOM); return(Remainder); } |
![]() |
![]() |
![]() |
#2 |
Jun 2003
22218 Posts |
![]()
Is it printing the value "21"? Or is it printing the value "2" and the next printf is printing the value "1"?
Try changing the first printf statement to Code:
printf("%u\n",powerM); Last fiddled with by Mr. P-1 on 2013-02-15 at 21:49 |
![]() |
![]() |
![]() |
#3 |
∂2ω=0
Sep 2002
República de California
101101111010112 Posts |
![]()
Consider also gaining at least a small amount of proficiency in step-thru debugging ... if you used e.g. gdb to print the variable in question, you would quickly realize it's your linefeed-less printf which is the culprit here, as Herr Pay-Minus-Eins also notes above.
|
![]() |
![]() |
![]() |
#4 |
Feb 2013
22·7 Posts |
![]()
Thanks Both. ><, thanks mr.P-1.
Yeah, I'm not really getting what "debugging" is beyond the more human mistakes...things like "well it doesn't work" ...is it the machine or me, or a little of both? I broke down and started using XCode for help a while ago after using text edit only, and discovered the "Analyze" function just now, so that should be a big plus for me, if it doesnt act as too much of a crutch. Maybe a learning tool. The issue was elsewhere. I was going modular in order to find if a large number was square, using the old school arithmetic technique similar to long division, built up into computer terms. I ran into another problem realizing that the carry-over/remainder number used to do the operation eventually gets very very large itself. I didn't realize that at first, and that was the real source of the whole problem. You wouldnt have seen it in that little snippet up there. thanks again Last fiddled with by Andrew on 2013-02-16 at 17:57 |
![]() |
![]() |
![]() |
#5 |
Feb 2013
1C16 Posts |
![]()
One more question, without making a thread out of it:?
Suppose I wanted to store one number in a CSV or another file, as in, write into it once, and read out of it. Say, 2^x or [y*(10^x)]. Roundabouts, how big could this CSV file get in the powers of 1000s, 1000000s, 1000000000? I mean in terms of hard drive space? Size of a high res photograph? video? |
![]() |
![]() |
![]() |
#6 | |
If I May
"Chris Halsall"
Sep 2002
Barbados
23·3·461 Posts |
![]() Quote:
Maybe. But, IMO, IDEs just isolate the programmer from the "metal". Yes, they can expedite development, but often it's a bit like giving a chain-saw to someone not trained in their use.... |
|
![]() |
![]() |
![]() |
#7 | |
If I May
"Chris Halsall"
Sep 2002
Barbados
1106410 Posts |
![]() Quote:
For fun, try this under a Unix variant some time... ![]() Code:
cat /dev/urandom > /tmp/fill_your_filesystem.csv |
|
![]() |
![]() |
![]() |
#8 |
Feb 2013
1C16 Posts |
![]()
Didn't even know there were step by step debugging tools. I'll google around, thanks.
No one ever taught me this stuff, I just started doing it, so forgive me. And I've never had a real use for real languages till I started following the primes searches. I mean I used "E-views" if you've heard of that, and "R" to run through stat and econometric courses, but the end-goal there was 'major' material, not other-major material, and that doesn't really count as its still built on top of a UI. XCode does make things nice and neat. |
![]() |
![]() |
![]() |
#9 |
Feb 2013
22×7 Posts |
![]() |
![]() |
![]() |
![]() |
#10 |
Feb 2013
22×7 Posts |
![]()
Well I went ahead and ran a large one.
1,000,000,000 * 12 digits, plus a comma for every 3. so ~ 12,004,000,000 characters. 1.6MB So that's what my old photo class photo's were doing. Sound right? |
![]() |
![]() |
![]() |
#11 |
∂2ω=0
Sep 2002
República de California
101101111010112 Posts |
![]()
When I bought my macbook "amateur" 4 years ago, I expected to do mainly 64-bit code-dev (SSE2 inline asm ported from 32-bit) on it, and also had high hopes that the Apple IDE might also prove useful. The very first C file using any inline ASM I attempted to build, I immediately hit the issue that the Apple IDE makes "special internal" use of the x86 *bx register in a way which is not transparent to the assembly coder, i.e. in order to get a working build I needed to plow through thousands of lines of inline asm and replace the *bx register with some other available general-purpose register. When it became clear that the resulting build was no faster than a simple gcc command-line build and that I was spending nearly as much time dicking around with the IDE as looking at code - to say nothing of the nightmarishly bug-riddled Xcode editor (which friends @Apple confirm is something of a running sad joke within the company, alas a sad joke with friends in high places, apparently), I stopped using it. Simple gcc/gdb serves me well. Meaning my next laptop will likely run Linux.
Last fiddled with by ewmayer on 2013-02-16 at 19:57 |
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Rho code | Happy5214 | YAFU | 3 | 2015-11-01 21:54 |
Please help me with my code | daxmick | Programming | 15 | 2014-02-14 11:57 |
New Code | JohnFullspeed | Programming | 20 | 2011-09-04 04:28 |
Code | Primeinator | Software | 20 | 2009-06-11 22:22 |
A little help with VBS code | IronBits | No Prime Left Behind | 6 | 2008-11-12 14:23 |