mersenneforum.org Code Help
 Register FAQ Search Today's Posts Mark Forums Read

 2013-02-15, 21:34 #1 Andrew     Feb 2013 22×7 Posts Code Help 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); }
 2013-02-15, 21:48 #2 Mr. P-1     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
 2013-02-15, 23:33 #3 ewmayer ∂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.
 2013-02-16, 17:56 #4 Andrew     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
 2013-02-16, 18:03 #5 Andrew     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?
2013-02-16, 18:07   #6
chalsall
If I May

"Chris Halsall"
Sep 2002

23·3·461 Posts

Quote:
 Originally Posted by Andrew 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?
Oh oh... Programmers who don't know how to use step-by-step debugging tools are doomed to failure once they go a little past "Hello World".

Quote:
 Originally Posted by Andrew 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.
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....

2013-02-16, 18:12   #7
chalsall
If I May

"Chris Halsall"
Sep 2002

1106410 Posts

Quote:
 Originally Posted by Andrew Say, 2^x or [y*(10^x)]. Roundabouts, how big could this CSV file get in the powers of 1000s, 1000000s, 1000000000?
Since you didn't give "x" nor "y", infinite.

For fun, try this under a Unix variant some time...

Code:
cat /dev/urandom > /tmp/fill_your_filesystem.csv

 2013-02-16, 18:14 #8 Andrew     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.
2013-02-16, 18:18   #9
Andrew

Feb 2013

22×7 Posts

Quote:
 Originally Posted by chalsall Since you didn't give "x" nor "y", infinite. For fun, try this under a Unix variant some time... Code: cat /dev/urandom > /tmp/fill_your_filesystem.csv

2^50,000,000 say.

And that looks dangerous

 2013-02-16, 19:47 #10 Andrew     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?
2013-02-16, 19:55   #11
ewmayer
2ω=0

Sep 2002
República de California

101101111010112 Posts

Quote:
 Originally Posted by chalsall 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....
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

 Similar Threads Thread Thread Starter Forum Replies Last Post Happy5214 YAFU 3 2015-11-01 21:54 daxmick Programming 15 2014-02-14 11:57 JohnFullspeed Programming 20 2011-09-04 04:28 Primeinator Software 20 2009-06-11 22:22 IronBits No Prime Left Behind 6 2008-11-12 14:23

All times are UTC. The time now is 20:25.

Sat Jan 28 20:25:00 UTC 2023 up 163 days, 17:53, 0 users, load averages: 1.06, 1.05, 1.05