Sponsored Content
Full Discussion: fgets problems
Top Forums Programming fgets problems Post 302396165 by jim mcnamara on Thursday 18th of February 2010 12:43:15 AM
Old 02-18-2010
What Corona was saying - you probably have corrupted stack or heap memory somewhere earlier than the fgets call. This means there may still exist serious data corruption. You are just no longer trashing it to the point it crashes.

Does your output - even though code appears to work - seem odd? Pari is a bignum Math package, are your results reasonable? I would be inclined to seriously question the validity of the final value(s); can you verify independently? Please tell me you are not computing orbital data for earth crossing asteroids... Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

'make' problems (compliation problems?)

I'm trying to compile and install both most recent version of 'make' and the most recent version of 'openssh' on my Sparc20. I've run into the following problems... and I don't know what they mean. Can someone please help me resolve these issues? I'm using the 'make' version that was... (5 Replies)
Discussion started by: xyyz
5 Replies

2. UNIX for Dummies Questions & Answers

Problems with ld.so.1

I renamed ld.so.1 on a Sun machine running Solaris 2.6. Now I cannot boot the system and I can use only very few commands in Maintenance Mode. Can someone help me? (3 Replies)
Discussion started by: ciccio
3 Replies

3. Programming

fgets()

does anyone knows how to accept a command from a user.. i was wondering to use fgets(), but got no idea how to start it... (4 Replies)
Discussion started by: skanky
4 Replies

4. Programming

Problem with fgets and rewind function ..

Hello Friends, I got stuck with fgets () & rewind() function .. Please need help.. Actually I am doing a like, The function should read lines from a txt file until the function is called.. If the data from the txt file ends then it goes to the top and then again when the function is called... (1 Reply)
Discussion started by: user_prady
1 Replies

5. Programming

Question about NULL Character & fgets()

Assume client send the message " Hello ", i get output such as Sent mesg: hello Bytes Sent to Client: 6 bytes_received = recv(clientSockD, data, MAX_DATA, 0); if(bytes_received) { send(clientSockD, data, bytes_received, 0); data = '\0';... (2 Replies)
Discussion started by: f.ben.isaac
2 Replies

6. Programming

[C] fgets problem with SIGINT singlal!!!

Hi all, I have this method to read a string from a STDIN: void readLine(char* inputBuffer){ fgets (inputBuffer, MAX_LINE, stdin); fflush(stdin); /* remove '\n' char from string */ if(strlen(inputBuffer) != 0) inputBuffer = '\0'; } All work fine but if i... (1 Reply)
Discussion started by: hurricane86
1 Replies

7. UNIX for Dummies Questions & Answers

Problems with using less

Hello, I am having problems with using less on Linux version 2.6.18-92.1.17.el5 (brewbuilder@hs20-bc1-7.build.redhat.com) (gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)). I am using csh but have the same problems on bash. If I pipe something to less it works perfectly i.e. cat file | less... (9 Replies)
Discussion started by: z1dane
9 Replies

8. Programming

fgets problems newline

hello, i'm trying to write a C-program that reads a file line by line. (and searches each line for a given string) This file is an special ASCII-database-file, with a lot of entries. I checked the line with most length, and it was about 4000 characters. With google i found several... (4 Replies)
Discussion started by: p1cm1n
4 Replies

9. Programming

fgets read file line with "\n" inside

Hi, I have a string like this, char str ="This, a sample string.\\nThis is the second line, \\n \\n, we will have one blank line"; if I want to use strtok() to seperate the string, which token should I use? I tried "\n", "\\n", either not working. peter (1 Reply)
Discussion started by: laopi
1 Replies

10. Shell Programming and Scripting

while and do problems

Any ideas how to clear this error as it seems I dont understand if,do,while and els commands #!/bin/ksh set -x print "This script creates test messages" print "Please enter test case name" read testcasename echo $testcasename skipfield=Y while print "Do you want to skip this field... (4 Replies)
Discussion started by: andrew.p.mcderm
4 Replies
bignum(3pm)						 Perl Programmers Reference Guide					       bignum(3pm)

NAME
bignum - Transparent BigNumber support for Perl SYNOPSIS
use bignum; $x = 2 + 4.5," "; # BigFloat 6.5 print 2 ** 512 * 0.1," "; # really is what you think it is print inf * inf," "; # prints inf print NaN * 3," "; # prints NaN DESCRIPTION
All operators (including basic math operations) are overloaded. Integer and floating-point constants are created as proper BigInts or BigFloats, respectively. If you do use bignum; at the top of your script, Math::BigFloat and Math::BigInt will be loaded and any constant number will be converted to an object (Math::BigFloat for floats like 3.1415 and Math::BigInt for integers like 1234). So, the following line: $x = 1234; creates actually a Math::BigInt and stores a reference to in $x. This happens transparently and behind your back, so to speak. You can see this with the following: perl -Mbignum -le 'print ref(1234)' Don't worry if it says Math::BigInt::Lite, bignum and friends will use Lite if it is installed since it is faster for some operations. It will be automatically upgraded to BigInt whenever neccessary: perl -Mbignum -le 'print ref(2**255)' This also means it is a bad idea to check for some specific package, since the actual contents of $x might be something unexpected. Due to the transparent way of bignum "ref()" should not be neccessary, anyway. Since Math::BigInt and BigFloat also overload the normal math operations, the following line will still work: perl -Mbignum -le 'print ref(1234+1234)' Since numbers are actually objects, you can call all the usual methods from BigInt/BigFloat on them. This even works to some extent on expressions: perl -Mbignum -le '$x = 1234; print $x->bdec()' perl -Mbignum -le 'print 1234->binc();' perl -Mbignum -le 'print 1234->binc->badd(6);' perl -Mbignum -le 'print +(1234)->binc()' (Note that print doesn't do what you expect if the expression starts with '(' hence the "+") You can even chain the operations together as usual: perl -Mbignum -le 'print 1234->binc->badd(6);' 1241 Under bignum (or bigint or bigrat), Perl will "upgrade" the numbers appropriately. This means that: perl -Mbignum -le 'print 1234+4.5' 1238.5 will work correctly. These mixed cases don't do always work when using Math::BigInt or Math::BigFloat alone, or at least not in the way normal Perl scalars work. If you do want to work with large integers like under "use integer;", try "use bigint;": perl -Mbigint -le 'print 1234.5+4.5' 1238 There is also "use bigrat;" which gives you big rationals: perl -Mbigrat -le 'print 1234+4.1' 12381/10 The entire upgrading/downgrading is still experimental and might not work as you expect or may even have bugs. You might get errors like this: Can't use an undefined value as an ARRAY reference at /usr/local/lib/perl5/5.8.0/Math/BigInt/Calc.pm line 864 This means somewhere a routine got a BigFloat/Lite but expected a BigInt (or vice versa) and the upgrade/downgrad path was missing. This is a bug, please report it so that we can fix it. You might consider using just Math::BigInt or Math::BigFloat, since they allow you finer control over what get's done in which mod- ule/space. For instance, simple loop counters will be Math::BigInts under "use bignum;" and this is slower than keeping them as Perl scalars: perl -Mbignum -le 'for ($i = 0; $i < 10; $i++) { print ref($i); }' Please note the following does not work as expected (prints nothing), since overloading of '..' is not yet possible in Perl (as of v5.8.0): perl -Mbignum -le 'for (1..2) { print ref($_); }' OPTIONS bignum recognizes some options that can be passed while loading it via use. The options can (currently) be either a single letter form, or the long form. The following options exist: a or accuracy This sets the accuracy for all math operations. The argument must be greater than or equal to zero. See Math::BigInt's bround() function for details. perl -Mbignum=a,50 -le 'print sqrt(20)' p or precision This sets the precision for all math operations. The argument can be any integer. Negative values mean a fixed number of digits after the dot, while a positive value rounds to this digit left from the dot. 0 or 1 mean round to integer. See Math::BigInt's bfround() function for details. perl -Mbignum=p,-50 -le 'print sqrt(20)' t or trace This enables a trace mode and is primarily for debugging bignum or Math::BigInt/Math::BigFloat. l or lib Load a different math lib, see "MATH LIBRARY". perl -Mbignum=l,GMP -e 'print 2 ** 512' Currently there is no way to specify more than one library on the command line. This will be hopefully fixed soon ;) v or version This prints out the name and version of all modules used and then exits. perl -Mbignum=v -e '' METHODS Beside import() and AUTOLOAD() there are only a few other methods. Since all numbers are now objects, you can use all functions that are part of the BigInt or BigFloat API. It is wise to use only the bxxx() notation, and not the fxxx() notation, though. This makes it possible that the underlying object might morph into a different class than BigFloat. inf() A shortcut to return Math::BigInt->binf(). Usefull because Perl does not always handle bareword "inf" properly. NaN() A shortcut to return Math::BigInt->bnan(). Usefull because Perl does not always handle bareword "NaN" properly. upgrade() Return the class that numbers are upgraded to, is in fact returning $Math::BigInt::upgrade. MATH LIBRARY Math with the numbers is done (by default) by a module called Math::BigInt::Calc. This is equivalent to saying: use bignum lib => 'Calc'; You can change this by using: use bignum lib => 'BitVect'; The following would first try to find Math::BigInt::Foo, then Math::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc: use bignum lib => 'Foo,Math::BigInt::Bar'; Please see respective module documentation for further details. INTERNAL FORMAT The numbers are stored as objects, and their internals might change at anytime, especially between math operations. The objects also might belong to different classes, like Math::BigInt, or Math::BigFLoat. Mixing them together, even with normal scalars is not extraordi- nary, but normal and expected. You should not depend on the internal format, all accesses must go through accessor methods. E.g. looking at $x->{sign} is not a bright idea since there is no guaranty that the object in question has such a hashkey, nor is a hash underneath at all. SIGN The sign is either '+', '-', 'NaN', '+inf' or '-inf' and stored seperately. You can access it with the sign() method. A sign of 'NaN' is used to represent the result when input arguments are not numbers or as a result of 0/0. '+inf' and '-inf' represent plus respectively minus infinity. You will get '+inf' when dividing a positive number by 0, and '-inf' when dividing any negative number by 0. MODULES USED
"bignum" is just a thin wrapper around various modules of the Math::BigInt family. Think of it as the head of the family, who runs the shop, and orders the others to do the work. The following modules are currently used by bignum: Math::BigInt::Lite (for speed, and only if it is loadable) Math::BigInt Math::BigFloat EXAMPLES
Some cool command line examples to impress the Python crowd ;) perl -Mbignum -le 'print sqrt(33)' perl -Mbignum -le 'print 2*255' perl -Mbignum -le 'print 4.5+2*255' perl -Mbignum -le 'print 3/7 + 5/7 + 8/3' perl -Mbignum -le 'print 123->is_odd()' perl -Mbignum -le 'print log(2)' perl -Mbignum -le 'print 2 ** 0.5' perl -Mbignum=a,65 -le 'print 2 ** 0.2' LICENSE
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Especially bigrat as in "perl -Mbigrat -le 'print 1/3+1/4'". Math::BigFloat, Math::BigInt, Math::BigRat and Math::Big as well as Math::BigInt::BitVect, Math::BigInt::Pari and Math::BigInt::GMP. AUTHORS
(C) by Tels <http://bloodgate.com/> in early 2002. perl v5.8.0 2002-06-01 bignum(3pm)
All times are GMT -4. The time now is 11:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy