none of them create real objects which inherit from each other
if you abstract, then there is no difference to write :public Foo { ...} or { Base Foo; ... };
at least i see it that way
although you may think i'm trolling
In every OO language with which I have experience, it's the classes that do the inheriting, not the objects.
Prototyping is so much nicer, IMO.
er, prototyped OO that is.
at the end of the day, all code becomes a sludge of bytecode
bytecode?
i want to pass a multidimensional array of strings from one function to another, do some operations on the variable length strings which includes changing its content, I declare and initialise as follows char *myStrings = {"StrA", "StrB", "StrC"}, this is fine when I try to convert these to
lower case in the receiving function i get a segfault, can someone point out what Im doing incorrectly?
char *myStrings[] = {"StrA", "StrB", "StrC"}
or a beautiful stream of hex, which knows nothing of objects
http://c-faq.com/aryptr/pass2dary.html
I have a theoretical musing sort of question for the channel...
What's the smallest amount you'd need to fiddle with the C language, in order to allow for proper closures?
nested functions?
Not exactly a small fiddle
though that isn't the only possible way to do it.
you're allocating those on the stack if you do it that way
if you want to pass them to another function, you should allocate them on the heap
loather-work, Is it not the other way around?
loather-work: actually only myStrings is "on the stack", while the string literals are wherever static host storage duration objects are placed.
and that only if myStrings is not also static duration.
well, yes.
if you want to be 100% pedantic about it.
anyway, hopefully sie's looked at the faq entry.
loather-work: if i wanted to be totally pedantic about it i would argue the "on the stack" and "on the heap" too.
either way, the answer is to malloc() those regions and strdup() or similar into them.
then pass the array to the function by reference.
there is no pass-by-reference in C
the concept is there. instead of passing myStrings directly, you pass &myStrings, hence, passing it by passing a reference to the memory
i know, in C everything is a primitive
including pointers
you are passing a pointer by value. it's a way of simulating pass-by-reference
you are passing a pointer by value. it's a way of simulating pass-by-reference
just don't free() my pointer.
All without violating the C standard! Of course, I stepped out of it a bit.
uAll without violating the C standard! Of course, I stepped out of it a bit./u
uuAll without violating the C standard! Of course, I stepped out of it a bit./u/u
probably an instance of Step :P
any one here use plan9?
hi good day
i have this variable
char *value;
all-caps nick name?
how can i get element of this varibale....
element for element sorry...
A pointer variable has no elements. It stores a single value -- a char pointer value.
yeap...
Only arrays have elements.
but how can i get...
for example
if the varibale is "123"
First, initialize it.
every single character...???
A char pointer cannot store the value "123", it can only point to the first character of such a string.
But, if it did point to a string, you could use the subscript operator.
can somebody tell me what is pointer, I can understand that it points to some type (like int, char...). But when somebobody say POINT I thought like someone point finger to something, but computer is not human...etc. So, I always thought that pointer is address ?
It probably is an address, yes
it is just like "point finger at something".
That's likely how it's implemented in memory.
a pointer points to an address
char *p ; What I have said, in physical terms?
only sometimes.
ok, then it is not possible to have a pointer with a given string, get element by element of the string (that in this case y referenced by a pointer)
then p hold the memory address of you string, and *p the character (value) AT that memory address
does it matter, since it varies from machine to machine? the point is that p can point at a char object.
twkm?
Pointers cannot store strings, only point to them.
Yes, you may use the [] operator on pointers. In fact, you may _only_ use it on pointers since it is a pointer operator.
prec is even more terse than Zhivago!
twkm, I dont understand word POINT in physcal terms...memory, cpu etc...
Concision is a point of pride.
yes
why must you have a physical metaphor? how will you handle it when one platform does it differently than another?
I communicate much less tersely face to face.
But I write concisely and I prefer to read concise (technical) books.
char c; char *p; p = &c; /* this (p) points at that (c) */
Time is euros. Or pesos, or something.
i got the segmentation fault when i tried this...
twkm, I just want to understand , and on x86 platform for example, becaues I was programming something in assempler x86, and now I want to make comparations
you can't say 'or something' and claim to be concise
char *value; in some point value takes "123"
you must have run low on shekles, as you once used to use the entire nickname.
Hrm... here's a ponderance... I wonder if CIL could host an entire C99 + POSIX implementation...
printf("%s", value[0]);
Paste your complete program: http://rafb.net./paste/
ok...
%s wants a char*
fine. a pointer in c is a pointer in x86 assembly.
hehe
did you mean: printf("%s", value);
hmm? Ah, well, G is a special case, being an all CAPS nickname.
nope cause i look for "1" that is in "123"
twkm, I never heard that x86 assembler has pointers, just memories, and addressig types
i.e., a pointer is an object, whose value is the address of another object, so you load it into a register useful for addressing.
OK; so, in x86/gcc/Linux terms, a pointer is just an integer.
GUILLOT, then you want %c for charecter
not %s for string
/nick Guillot
and thus you will indirect using it. so that you load or store via [].
twkm, oh, how it is a little bit more clear for me
MOV EBX, p; MOV EAX, DWORD PTR [EBX+0]; MOV j, EAX
uh-huh. that it points at another thing is far too hard to understand.
it's okay if you don't get it
--still doesn't
At the machine level, a pointer is just an integer. It differs in _usage_, not in _form_
i just know where to use them
yep
how did you come to understand (stealing from LeoNerd) mov eax, [ebx]?
though "just an integer" is false on some platforms.
twkm, I understand that contents of address [abx] goes to eax?
but how did you learn it, if you can only learn the c pointer idiom by using assembly?
i.e., what allowed you to learn the assembly? and, frankly, why isn't that sufficient for c too?
anyway, hopefully you get it now.
Sally sold C libraries by the seashore
i never quite understood the in-lining of asm in C code... how does one access an int declared in a function if you inline asm?
"in a function written in C", that is
consult the compile documentation.
they all differ as to how.
twkm, I learned (understand) assembler because everything exist...I mean eax is a registar, registart is array of logical cicruti (I mean flip-flops) and flip-flops(logical circuit) consist of transistors etc...It is apsolutkly clear for me
i was hoping there was standardized notation for that. is there a resource in particular that you might have on hand for gcc?
http://rafb.net/p/LeWfJx82.html
or is http://gcc.gnu.org/ my best bet?
Please paste a complete program. Since dosomething() is never called, I can't testit.
ok
oh, so you learned how mov eax,[ebx] works by considering what the electronic circuits were doing. wow!
line 7: won't compile
there isn't. and yes, there.
line 7: use the standard idiom for iterating a string: for (i = 0; value[0]; i++)
line 10: missing return
It's how I understand it
I did electronics for ages before programming
electronics, ASM, C, perl... that order
line 10: Oops, I mean, fix your indentation.
Perl only really makes sense to me by considering what a C program might look like that implements it
line 21: doesn't compile.
C only makes sense by considering what ASM it might compile to
line 18, 20: use puts() instead
ASM only makes sense by thinking about what a CPU might do to execute it
twkm, yes, EXACTLY, I learnd that way
so you actually considered the actions of the thousands, millions or billions of transistors involved to handle all that? surprising.
MOV EBX, p; MOV EAX, DWORD PTR [EBX+0]; MOV j, EAX
No, not the whole lot
I learned about the bit-gnomes which live inside each CPU and shuffle bits around with their wheelbarrows.
C makes sense to me. But, in order for it to have done that, there were plenty of bits I needed to first analogise from ASM
I think it helps but I have to write down that line and to enovke my ASM memories, if I want to 100% understand, thanks
can you remember what the abstraction/notion just before indirect addressing, that lead you to understand it well?
i would have thought the "chalk pointer, pointing over there" sort of thing would work, for assembly as well as c.
No
Because, again, I know the silicon electronics
move EBX to the adder, add 0, shove the result on the address bus. Fire a memory read cycle. Wait for RAM time. Get result from memory data bus, put it in EAX
That's how I understand it
Granted, I don't need to think of all of that when I see the line; I inherently know what it does.
Same as, when I see a light switch, I know what it does. But in order to _understand_ how the switch works, I have to be aware of current flow and metals/nonmetals, and so on.
Actually, ASM makes a lot of sense if you first go via ERTL; Explicit Register Transfer Language
Picture a machine as nothing more than lots of registers and special logic functions; each logic function is stateless. Each ASM operation then becomes a sequence of register=function or function=register transfers.
That then translates into real hardware, by way of D latches and various types of logic gates.
gcc uses something along the lines of: register int *foo asm ("a5"); /* where a5 is the register you want the variable in */
that's really nifty!
And from there, down further into transistors, P/Ntype silicon, electrons and silicon atoms,... down into quantum phtsics
*physics
And it's about there, that I start not having answers to questions
i liked the bit gnomes explanation better
o, yes LeoNerd and it is very easy for me to undestand(when somebody say memory location memory address etc), but when somebody say POINTER, I am a little bit confused,
OK, then pointer == memory address.
Uses of it, just translate into various ASM instructions to use it as a memory address
LeoNerd, great
int i = 0x80013894; int *p = &i; == it may be that i and p look the same in memory
As far as the machine is concerned, they're just two numbers. It's only C that makes the distinction between pointers and integers, not ASM.
but LeoNerd is it possbible to write some very simple program in C and than dissassembe it? to see exactly what is a pointer
Yeah.
hrnt Bit gnomes are real. Don
i would not recommend it
hrnt Bit gnomes are real. Don't let anyone tell you otherwise.
You probably want to -O0 though, to turn off all the optimising
consider reading your compiler's documentation.
Otherwise the optimiser will probably rewrite the ASM code into something (hopefully) equivalent, but likely less readable
i won't
main() { char *p}; and that when dissasm to see that (I mean pointers etc)?
you'd get 1458976 pages of asm code
Um... that program doesn't do anything
It'll probably compile to nothing
LeoNerd, and what shuould I write?
you don't need to disasm if you use gcc. you can use the switch -S to produce the assembly output
int i = 10; int *p = &i; *p = 20; int k = 40 + *p; *p = k / 2;
on at&t syntax unfortunately.i can't recall what was the switch to tell the compiler to use intel syntax.
That hopefully has enough magic numbers in, that the ASM will look readable
ok, LeoNerd let me try...
stop drooling over seeing some assembly. take what your book says to do to learn to use a pointer, write the program it provides or suggests. *then* look at the assembly.
if there was one
prec, http://rafb.net/p/zIVtX156.html
im trying to write the main code that seg fault
don't you hate it when you have a problem and you can't see wtf is wrong, but you know it's something simple and it takes like 15 min of staring to finally slap your forehead and say wtf did I type that for?
foo.c(39): warning #967: conversion from "char" to "void *"; sizes do not match
and a bunch of other issues. turn up your warning level.
mmm i miss the includes in the paste
prec, http://rafb.net/p/ZdyNj588.html
atoi takes a string, not a char
else you could only get numbers from 0 et 9
?!?!? *boggle*
thanks twkm and madx
mmm im trying to cut all the code that it is no necessarily
in the line 46 how can y convert this char to int..???
???
/nick /Guillot
line 3: what??
line 2: Why?
line 6: Do you really need this here?
line 12: int main(void)
line 16: failure to check return value of malloc
uis plainte a mac
lines 14-17: Why not use an array? char string[] = "123";
mmm that my headers, of all the program im trying to write only the code that matters
line 31: Use the standard idiom.
lines 31-34: What is this loop supposed to do?
line 46: broken, as twkm said.
trying to get charcater of character of the string in order to put in a lcd
line 46: avoid atoi, use strtol instead. But if what you really want is to convert a digit character to its value, then simply subtract '0'
precZ
Am I Hungarian notation for "pointer-to-record" ??
maybe in pascal
var prec^ : somerecord;
^somerecord; :P
you mean (* :P *)
or { :P }
Only in "new" Pascal. :P
if i wanted to write a very simple very quick GUI in C on secure linux web hosting what would i use?
some gui library
...
i dont have any other way to say this but... no shit sherlock.
I would use GCC
use GTK+
okie dokie.
the preprocesor isn't weird!
... C++ is weird
nothing is weird as long as you know what you are doing
but cpp is not.
indeed. C++ is tortuous though.
learn obj-c and you'll forget c++
heh i did look at it
smalltalk looks nice as well
bigtime
How would one go about checking the country of an IP?
I mean
Is there a database hosting or something somewhere?
let's traceroute it
Um
various ones. often weird, and sometimes wrong.
geoiplookup, it's a perl script or something
nothing of which is particularly c related.
thanks allah
lol
twkm, I know, but this is the closest to a general programming chan I know of that doesn't suck.
you help make it suck. thanks.
twkm, does it help that I'm writing the program in C?
but didn't discuss a word of the c? not really.
hehe
and in my make file i have -L/usr/include/gtk-2.0, yet i get that it cannot find the header.
C doesn't have "imports".
my bad, #include
The preprocessor directive #import, if it exists, is a vendor extension.
Try pkg-config instead.
im not using #import im using #include.
Use pkg-config to generate the correct C compiler flags.
i've never written a linux program, whats that do?
*sigh*
to add insult to injury, im not an experienced c/c++ programmer either, i make my living programming Java.
thrilling.
hmm
sounds like what you need is gtk support, not c programming.
frustrating.
You're using gtk on Windows?
no, on linux
OK, so man pkg-config.
why?
i did, it asked for a package name
so you might understand something?
man pkg-config
The output of the man(ual) command is a manual for the indicated utility.
It is intended for the consumption of the brain of the prospective user.
Brains feed on documentation; hungry brains are of much less use than well-fed ones.
not why to the man, i thought you told me to do it again.
not why to the man, i thought you told me to do it again.
in the make file, are you supposed to have multiple -L 's for each include directory?
when required.
then how come adding the directories required did not result in the compiler finding them? if i did the full path to the header file, it works fine.
CppIsWeird http://www.gtk.org/tutorial/ see 3.2 especially
something wrong in the specification. just what i cannot say since you shared nothing concrete, only impressions.
End world brain-hunger -- read the documentation.
ok, i got it. Thank you.
What happens on *nix systems when two processes try to read from a FIFO at the same time?
one blocks?
that isn't always the case
is it system dependent then?
I don't know
tar cf - /largefile |ssh localhost tar xvCf / - ## oops
never do this!!"
what OS are you using?
Linux
what does C do?
Change directory to / so that you are actually reading from and writing to the same file.
what does that accomplish?
GNU tar complains; I suppose the files are OK.
I expect the files would be okay anyway
Well, I didn't actually use localhost, but I used another name which points to the same machine.
you can't write something you haven't read yet can you ?
The net affect, I suppose, is to allocate a fresh inode and disk sectors for every file copied.
A no-op which unnecessarily consumes resources.
ooh, defrag!
well, if you start with enough free space ;-)
er.... yeah.
Disk is cheap, right? Just buy a second disk, copy all your files to it, then reboot.
hahaha
Repeat this weekly or monthly, swapping disks each time.
I think it might be a good idea to use a CD to perform this process...
What's the utility function to convert from raw IP address to string?
what type is the raw ip address currently?
hey, is there a way to static link to windows libc ??? This makes sense!?
Are you asking this question because you're compiling using a Visual C++ "Express Edition", by any chance?
hello
An IPv4 address? Usually inet_ntoa().
thanks, but I found it
no, a friend mine asked how to compile a ISO C prog statically in dev-cpp ...
I am trying to get my binary search for an array of structs to work, and I can't seem to find my problem
its running too many times, would anyone please take a look
Under Windows though, I recommend using WSAAddressToStringA() if you want IPv6 compatibility.
http://rafb.net/p/zQSppBz54.html
nah, i know they're ipv4 addrs
your paste could not be found on the server
Is there any way to ping from C other than using SOCK_RAW?
system("ping host");
http://verplant.org/liboping/
a href="http://verplant.org/liboping/"http://verplant.org/liboping//a
http://rafb.net/p/zQSpBz54.html
Dustin apparently typed the URL by hand.
do i need some kind of a mutex with fork() or how do i make sure i don't access memory at the same time at 2 "threads"?
fork() doesn't create a thread.
thanks
prec, fork() creates a new process by duplicating the calling process.
Yes.
okay..
then can i interchange information between those 2 threads?
They are not threads, they are separate processes.
via interprocess communication yeah..
Use any of the available IPC mechanisms.
WHATEVER
no need to shout, we can hear you just fine.
don't shout, it scares Zhivago
The memory is not shared, it is copied. You must use IPC at that point to share information.
its not threads!!! not whatever :
only ipc?
the new process gets a copy of the original process's data. its not shared
If you want threads, use threads.
Well, they are threads, but they are not running in the same process.
jasta, and i can't hand a pointer to the other threads stack somehow?
IPC stands for ...
prec, ORLY
kthxbye
You may not. Does that sound like IPC to you?
Perhaps you should instead use threading if that is the effect you desire.
if you need to pass data like that, dont fork, use threads
Allah, Z is frightened of his own shadow.
Yes, by definition, you can only communicate between processes by using interprocess communication.
What are you really trying to do?
prec, overwhelming argumentation
Write a program in C language with the name prsref which will act as a referee in a game of rock, paper, scissors between a child process of the initial process that creates the program and anotherr process that has created the program prs (which you also have to imlement in C) which is run in
another computer that communicates with the parent process via stream sockets.
is this homework?
We will not do your homework for you, btw. It's in the FAQ somewhere.
not really
OK. Why don't you use, I don't know, stream sockets?
sure worded like homework
s/home// actually
Since that is the IPC mechanism which has been specified.
Maybe it's an interview question?
umm yes, that was not the problem
I sincerely hope he fails that interview, then.
question was if i can interchange information in a straightforward way
but that doesn't seem to be the case
what exactly does "straightforward" mean?
char *bah;
bah=myvar;
...
Does it mean in a way that you can understand? If so, then no, I doubt that is possible.
oh damn!
can I quote what you said about 20 or so lines up?
it means not having to use IPC ffs
No, processes do not share memory space, unless you are using shared memory. Guess what, that's an IPC mechanism too.
Go for it.
do you like to be stupid jasta ?
so much hostility
you guys should really get laid
It's all in your head.
sure, MY head
Repetition teaches a donkey.
not me tho
Repetition teaches a donkey.
not me tho
hmm, I thought donkeys learned better through corporal punishment.
true zhiv
More specifically, the repetition of corporal punishment.
haha
Although captial punishment "works" in the sense that the learning disability is no longer present.
But repeated captial punishment is just beating a dead horse.
damn it prec, you beat me too the obvious joke
OK, OK, I'm done now.
Is to be learned that absence of disability or the presence of ability?
can you rephrase that question in English?
Z, as I believe it to be coherent english (US) I do not feel I can increase its cohrency.
well, your belief is unfortunately incorrect.
Incorrect it may be, but one choses their own fortune.
yeah I guess that's why so many people chose to be shot in WW-II.
What the hell..
What has that to do with fortune?
Can you even START a question with "Is to be learned"?
don't you know what 'fortune' means?
Yes, it is a variety of cookie.
let me know when you have gotten over this bout of stupidity.
Zhivago, if the goal of this is to say that we have a 'destiny', then the argument is lost on me, for I have not seen any come to an end that they did not create.
ok, so all of those people created themselves getting shot in WW-II?
aborted fetuses?
Z, why were they in front of the bullet?
because they were jewish?
vorpal, prove that a fetus has cognition and I will argue the point.
when does cognition begin, in your estimation?
ah, no reply, I see.
Z, I am trying to frame a response that I can defend.
let me know if you manage.
Z, they died because they were incapable of escape.
so, they created that inability to escape?
no, they chose not to
this is starting to sound like Russian-reversal ;-)
hmm, did they choose not to be able to walk through walls?
or was it something else that they didn't choose?
Java started as a project called "Oak" (The name came from an oak tree that stood outside the Sun Microsystems office) by James Gosling in June 1991 for use in a set top box project.[3] Gosling's goals were to implement a virtual machine and a language that had a familiar C/C++ style of
notation[4]. The first public implementation was Java 1.0 in 1995. It promised "Write Once, Run Anywhere"...
...(WORA), providing no-cost runtimes on popular platforms. It was fairly secure and its security was configurable, allowing network and file access to be restricted. Major web browsers soon incorporated the ability to run secure Java "applets" within web pages. Java became popular quickly. With
the advent of "Java 2", new versions had multiple configurations built for different types of...
In 1997,Sun Microsystems approached the ISO/IEC JTC1 standards body and later the Ecma International to formalize Java, but it soon withdrew from the process.[5][6][7] Java remains a de facto standard that is controlled through the Java Community Process.[8] Sun used to make most of its Java
implementations available without charge though they were closed-source, proprietary software. Sun's...
Java is a programming language originally developed by Sun Microsystems and released in 1995. Java applications are typically compiled to bytecode, although compilation to native machine code is also possible. At runtime, bytecode is usually either interpreted or compiled to native code for
execution, although direct hardware execution of bytecode by a Java processor is also possible.
The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. JavaScript, a scripting language, shares a similar name and has similar syntax, but is not directly related to Java. Java is particularly object oriented and is quite popular
because of this.
!botsnack
Z, they could have fought back and died in physical confrontation.
+ 3.1.5 Swing application
* 4 Criticism
would that have affected their escape?
o 4.1 Performance
o 4.2 Look and feel
ah, so they chose to be shot without fighting rather than to be shot with fighting.
o 4.3 Object Orientation Caveat
let me know when this bout of stupidity has passed -- your reasoning implies that everyone is omnipotent.
Zhivago, no the point is the could be beat to death.
*they could be
no, your idiotic point is that they chose it.
Hello. I have a while loop that prints a single statement before scanf(); however, the printf() seems to have some echo effect. How can I stop that?
we do not determine what happens to us in large.
paste the code and testcase at rafb.net
candide is a b it more liberal these days ;-)
any suggested usenet client ? I've been searching for a while.
I found 'tin' acceptable.
but I don't really have a recommendation.
http://rafb.net/p/EOUybd84.html
vorpal, I did not say they could escape, I just said their death did not have to be by bullet
The code creates a pyramid of letters.
Is there any particular reason you're mixing scanf("%c", ... and getchar() ?
I initially tried scanf() inside the loop; for some reason, it didn't work. So, I used getchar() to achieve the desired effect.
actually thunderbird was named icedove; the subfolders don't appear in the folder list, the program offers no options for creating, saving in, viewing, etc. any subfolders
"for (row = 'A'; row = ltr; row++)" // What makes you think 'A','B',...,'Z' will be guaranteed to be sequential?
you have opted for the "try-random-shit-until-it-appears-to-work-method"
Guilty as charged.
I was under the impression that only '0','1',...,'9' are guaranteed to be sequential.
that is correct.
However, I have been trying out something new; try and step through what the program should do before typing.
That is new? What was the old method?
LordOllie, not really much of a method. Just plodding through.
Ah, I thought it was the hack and pray method.
To answer your question about the sequence, the example in the book was in sequential order.
"Hack and pray" sounds apt.
Is it improper?
yes, very much so, planning makes programming more enjoyable
Sounds discouraging.
Yes; it is not guaranteed to be sequential on any given platform.
Oh yes. I was working on the assumption that the ASCII table is the model used.
A more portable solution might involve: const char characters[] = { 'A', 'B', 'C', ..., 'Z' }; and then using a "for (size_t index = 0; index characters_array_size; index++) " instead: referencing characters[index] inside the loop.
You beat me to it! That was the alternative mentioned in the book.
I really appreciate portability; I will adopt the approach you mentioned.
How about the printf() echo?
The scanf() isn't eating the '\n' in the stream.
There's no echo; that loop actually iterates twice, causing that effect.
That traitor!
The first iteration through the loop, it gets the newline that scanf() did not remove from the stream.
I thought the problem was _inside_ the loop! Is there a way to work around ever using scanf() in a function.
I heard it's bad form to use it.
That, and gets().
"scanf() in a program"
the problem with scanf is that it does input and parsing in one step. if the parsing fails for any reason, it is difficult to recover
Are there preferred alternatives to using scanf()?
the answer is to break it up in to two steps. input into a buffer, and then attempt to parse the contents
If you just wanted to throw together something quickly, without much caution for handling erroneous input...
You could replace both the scanf() and the getchar() lines with: do ltr = getchar(); while (isspace(ltr));
But... perhaps you should invest time in designing it properly... e.g. perhaps line-based input is more what you need.
if you must scanf, then at least check the return value to make sure it successfully parsed whatever you were expecting
also, be careful to avoid buffer overruns when attempting to parse strings with scanf
line-based input? What's that?
Will do; does declaring the size of arrays help avoid buffer overruns?
restricting the amount of input prevents buffer overruns. with scanf you would use a format specifier to do this
format specifier? as in %f ?
do ltr = getchar(); while (isspace(ltr));
Thanks for all the feedback; will work to revise the code based on the suggestions.
TTFN.
I have a float data type used for a scanf function. How do I make my float data type = x.2200 instead of x.22xx when I type in x.22 into the keyboard?
look up floor()
What Every Computer Scientist Should Know About Floating Point
Google that, and read it.
In C, floating point is not decimal, but binary.
is fread handled differently on windows in comparison to linux in how it handles EOF?
The way your code uses fread() on both systems, should be the same.
You probably want to use binary streams, not text streams, with fread().
I am... it seems that when it hits the end of file, it flags an error on windows, and returns 0...
as opposed to linux, where it reads to the end, and returns the bytes read
http://rafb.net/paste/
It's possible that either vendor has written a bad implementation of fread.
You're using feof() and ferror() to distinguish between a read error and an EOF condition, right?
yeah...
s/and/or
You're not calling feof() until you have a reason to, right?
I'm calling it after performing the read...
Why?
Yes, should the code instead of the guessing game. :|
ok...
s/should/show/
After performing the read _only_ if the return value of fread() is less than the third argument passed to it?
the whole file, or just the relevent section?
ideally you would proved a minimal testcase demonstrating the problem.
s/proved/provide/
Don't use feof() unless fread() returns 0
http://rafb.net/p/3vknmb87.html
So, the problem is that you are calling ferror() and/or feof() when you have no reason to do so.
oh...
Do not use either of these functions until or unless a previous I/O operation returned an eof-or-error condition.
MASSIVE_NUMBER? lol
1L ? Hmm.
i suppose you must also have a MASSIVE_BUFFER
The only remedy for the above is visiting http://jeyes.ytmnd.com/ and listening to the music loop a few hundred times.
Or reading http://www.c-faq.com/stdio/feof.html
I have an idea of how large the file is already
Or prec's suggestion comes a close second.
OK, then a REASONABLLY_SIZED_BUFFER
it is reasonably sized..
except when it's not
at the very least you should check the file size.
that has been done when the buffer output_pos has been malloc'd
the buffer output_pos is pointing to*
what's happening is that this segment works on linux, reading to the end of file...
but on windows, it returns 0, and flags an error.
whaat error?
well, ferror(f2) shows one
i also noticed that you are fseeking before the fread. how do you know that you are fseeking to the same position?
xystic, I don't see how flor() would solve my problem
*floor()
if I input 2.22 using scanf, I'm getting 2.22xxxxx, I want 2.2200
xxx?
random numbers
Random? Surely not.
You could just display "2.22" with a format specifier.
yes
e.g. %.2f
but my calculations would be wrong when I do arithmatic
Did you read that paper yet?
Your calculation will always be within an epsilon anyway... (because doubles/floats don't necessarily store exact precision values)
http://docs.sun.com/source/806-3568/ncg_goldberg.html
Simply put, you can output only "2.22" easily. But if you _must_ have 2.2200 (or rather, as close an internal representation to it as possible), and your input was something like 2.2245436 then you can facilitate floor() in some convoluted way to achieve that.
e.g. floor(input*100)/100 or something equally horrid.
If, by chance, you are wanting to compute currency information in US dollars (or euros, or CHF, etc) please consider instead performing your calculations in cents.
but... you don't want that.
YES
I am precisely trying to convert currency
Use integers.
Yeah, I would use integers for those currency calculations then.
how do I input decimals with scanf and integers?
Do you have a good book on C? It should tell you...
I wish I had one
could you please briefly tell me how I would accomplish this with integers?
* floating point by 100
and store it into an integer?
Using floating point for any part of your calculation will be a problem.
Look for a library that provides a currency type.
Do not use int.
You could use strtol twice.
Especially if this is a financial application dealing with large amounts.
oh gawd
anyone interested in idling in #garfield for a bit for me, its part of an interesting social experiment
a social experiment you say? perhaps to see how many dolts you can lure into a silly channel?
oops, didn't see the administrative action ;-)
social action!
that stuff used to be highlighted in my previous client
hehe
I am 3 days into C, and I know this question is going to get me smacked but I am bold enough to ask it anyway
bprice20, where's your C book?
when I run gcc against my program with -Wall its spits out suggest parentheses around assignment used as truth value
a sign of sagacity.
it is a style issue.
and perhaps a reminder.
while(row = mysql_fetch_row(result))
should I just ignore it? and if not how do I make it go away, I mean I may as well learn the correct style while I can
before I go making code in 3 years thats ugly
"correct" style. hmm.
bprice20, it's a warning; you either want to know it's there or you don't
The compiler is reminding you that this particular construct can be a major pain.
teh intranez is my book.
The () that it suggests you put in is to assure the compiler that you know what you are doing.
add the extra parens, and the error goes away. the wanring is a useful one because at some point it will tell you that you are using an asignment when you meant to use a comparison
what does it mean by "truth value"
if ((x = 2))
vs. if (x == 2)
x will always = 2
oic
sometimes if ((x = y)) is what you mean, in which case putting in redundant parentheses makes it obvious.
personally, I'm not a big fan, but it appears to help some.
The thing is, when I add the parentheses and make it while(row = mysql_fetch_row((result))) I still get the warning
ugh
so is the compiler just being retarded and warning me that hey that may not be what you want * just in case
Please read Zhivago's example again.
you didn't add them.
when writing recursive functions in C, is there a max recursion depth that must be worried about?
at least, not to the if.
yes, and it is undefined.
essentially you should worry about it about as much as running out of malloc memory
ok I get it now. Thank you
Zhivago, oh.
all very implementation dependent.
right
hrmmm
Zhivago, Woul d you happen to know for which positive x, cot(x) = 2/3 ?
Zhivago, then I wont worry about it unless it becomes a problem!
Zhivago, thanks for info.
not in my current, zombie like state.
hmm, that bot really needs to have lag compensation or something.
?
that quiet will wear off in a bit.
I don't think that's practical...
Don't do anything obviously stupid and you won't need to worry about it.
yes, x = atan(3/2)
vorpal, In terms of pi, that is...?
Uhm, when I use putchar('\n'); on DOS it actually writes two bytes (I guess \r\n). How can I fix this?
freopen stdout as a binary stream
Erm, offe-topic...
this is a feature, though.
Windows uses \r\n for line endings.
capso, perhaps you meant to ask in #trigonometry
Jafet, It doesn't hurt if he can answer.
vorpal, It's all right if you cannot provide an answer.
i could, that's not the issue
Zhivago I am writing a .bmp via stdout (redirecting with ), so I would like this not to happen.
well, then see above.
ok I have another dumb one; when you initialize an int, does it initialize to 0 without needing to go back and say for instance
I fixed the problem
but I suggest not doing this.
int iter; then iter = 0;
I don't think that's a good idea. Things can happen with stdout.
um, when you initialize an int, it is initialized to the value that you initialized it to.
If you really want to write images, I suggest a more reasonable format like PPM.
perhaps you aren't initializing it ...
It supports ASCII text modes.
I am new to c, what is the difference of || and &&?
where is your C book?
here
But... my program ALMOST works, except for this. In other operating systems it works :-/
chee || means or and && means and
then bloody well read it!
and then ask a more intelligent question.
oh, ok, thanks
C says nothing. You should assume nothing.
only by accident.
anyhow, I suggest that you allow the user to supply a filename
so if you need it to be true if either condition use ||, if its only going to be true if both are use &&
you can supply um, ":con" or whatever it is.
bprice20, thanks
Zhivago actually, I am doing this in assembly language, so I wanted to this as simple as I could, that's why I didn't allow the user to supply a filename.
I interface with C, tho.
chee, I am just trying to get some cool points to use up when I have more questions
vorpal, Oh, come now. If you could you'd have done so without hesitation.
um, so how are you using a FILE *?
ok, when I have more.
read first, ask second.
I knew that, Zhivago, but my english is really poor. my C book is written in English.
ok, but try to make it a better question than "what is &&?"
Zhivago using C library from assembly.
And compiling with gcc my .s files.
ok.
Weeell, I suppose we can dispense with all pretense of portability in this case.
Bah, I just compare if the character I am going to put is 10, if it's, then I change it for 9
Which is more or less the same in binary
(My output is a 2 colors bitmap, so a bit per pixel)
is there a bigger integer data type than long int?
long long in C99.
http://gmplib.org
err
I'm trying to get a precision of 2 decimal places
when I do a scanf of 2.22, I want 2.220000, not 2.22432432
using a floating point
I was trying to multiply it by 100, store it into an integer, multiply it by 1000, then store it back into my floating point and divide it by 100,000
why?
I mean, why do you want 2.220000?
I'm trying to convert currency
using floating points in any stage of a financial calculation is bad
so, why are you using imprecise numbers?
This is where you reply with, "I think you're in the wrong channel, sweetheart".
I suggest that you calculate this with integers, measuring some appropriate quanta.
say, cents.
the basic problem you have is that binary fractions cannot accurately represent all decimal fractions.
I believe he is aware of that already.
well, how do I print out the results?
however you like.
Results of what how?
I believe that he is aware of a symptom without necessarily understanding the cause.
how to print all the characters between a and z?
print out the results after the currency conversion
A loop would work.
I'll still need 2 decimal places
It's not uncommon to deal with currency values as more than two decimal places.
printf("%d.%d",dollars,cents)
It's used often in corporate finance, when dealing with international financial management.
Wrong.
oh great...
whoops
MNE's represent many of the currency conversion rates to 4dp accuracy, maybe more.
pretty much have to rewrite th eprogam then
no, you'll need to _print_ two decimal places.
well, that's what happens when you make stupid decisions at the start.
but it isn't that bad.
This is my cue to insert shameless plug for C++ and generic interfaces.
just keep cents, and printf("%d.%d", cents/100, cents%100)
if you have no grasp of the problem at hand, sure.
How big are your numbers going to be?
something like 1234567.89 ish?
max
Ask the bank software to not initialize your account variables.
why not use a 64 bit integer?
which data type is that?
well, 1234567 is very small
uint64_t?
int64_t or something.
Jafet, I know how to use a loop to print numbers, but how to print chars?
Use your imagination.
123456700 cents fits into 32 bits happily
ah,ok
And your book, if it helps.
see: showcfont
ok
The references to C99 stuff is almost refreshing, compared to yesterday.
s/is/are
What about debts!?
Jafet, they're..... well... there.
Are you sure you're asking the right question?
xystic, maybe not.
k
ok I am confused. If I do a printf, and in that printf I use an int named for instance iter in this manner; iter++ why does it not only output the value incremented by one but actually increment the value of the variable by one?
how about when I use scanf to input a decimal number
how do I do that with unsigned int
what does iter++ mean?
for example printf("\n---------------------------------------%d---------------------------------------------------\n%s\n%s\n%s\n", iter++, row[0], row[1], row[2]);
!book volt
do you have a C book?
we don't need horrible examples -- answer the questions.
no, what book do you recommend
"The C Programming Language" by Kernighan and Ritchie.
go and get it, and stop wasting everyone's time.
libraries may be useful
inter++ should mean to increment the value of the var inter by one and output that
"Dune" by Frank Herbert.
++iter
'nuff said
I have no problem buying and studying a worthwhile text
Alice in Wonderland.
unfortunately what you think "should" happen is wrong.
what kind of question people can ask here then?
x++ evaluates to the prior value of x.
intelligent.
read your book -- when you get confused or stuck, then ask a specific question to help you understand it.
don't ask "what does 'a + b' mean?"
or 'what's an int'?
for the less technical (how to print a character) question: printf( "%c", it );
ok
Or see putchar.
if you want to ask "why does a + b equal c rather than d?" then that's more sensible.
because it shows what you think, and why it's wrong, and what you want explained.
showcfont has to do with how do I appropriately increment a char and properly display the result
ok, I see
just bought The C Programming Language
hurrah.
now explain the difference between x++ and ++x.
I'm sure he can when it arrives
that's ok -- I can wait.
x++ apparently returns the previous value of x, although I thought it incremented x by one and returned that
um, I'm getting 0 when I try to print out an unsigned 64 bit int with %d
what does ++x do?
what does %d print out?
0
++x apparently does increment the value of x by one
gonna try %u
no, read the goddamned documentation for printf, and tell me what %d does.
why not try literacy?
they both increment x by one.
the difference is in what the expression evaluates to.
integer format specifier
oic
%i integer, %d decimal integer, %u unsigned integer, %ud unsigned decimal int
not integer, but 'int'.
type 'info libc' at another terminal and you should like what you see
so, what modifier do you need for a long or long long int?
now you can consider x = x++;
what does this mean?
%i ?
read!
can be hexadecimal, say with %xi
...of course
functional literacy is not optional if you want to pretend to be a programmer.
though you can have hexadecimal, say with %x
hi, how do I use a float as an array subscript? thanks
look for "formatted output"
why would you want to do that?
have more problems
now
How does it make sense to use a float as a subscript?
Is what you really want, some kind of associative container, that maps a float to some other type?
it's under "i/o on streams"
long story, but even without, say I have a 3.5 and the lookup is under array[7] I want to be able to say array[float*2] without assigning float * 2 to an int first
are you aware of casts?
and what happens if you have 3.4999999999999 ?
I am ... would I say array [(int) float * 2]?
um, if you want 3 * 2
but if you want 7, then you'll want to cast the result of the multiplication
I won't have 3.4999, it has to be either x or x.5
ah, you don't understand floats
but in that case, why aren't you just using integers?
thankyou Zhivago and klys
welcome.
np
cause i need to be able to represent 3.5
are you saying floats are never 100% accurate?
because of the binary representation?
which binary representation?
of the float
and how does C represent floats?
with a radix, mantissa ... it's been awhile
floor(), ceil()
For future reference, for your uint64_t variables, you might want to look into PRIu64 .
rintf() for proper rounding
in an undefined fashion.
meaning?
meaning it depends on the compiler.
so you can't expect that it can represent 4.5 exactly
but, if you're using i/2 for i is an integer, why aren't you just using i, and then dividing by two later?
well, it can represent any division by a power of 2 accurately
and where does it say that?
you're storing the mantissa in binary
and where does it say that?
what form is the mantissa stored in?
where haven't you been using binary today, it's a defined number of bits in your float or double
and what do those bits mean?
I see ... the issue is that I am getting user input which is in the form of 3.5 years. In order to find a special factor for 3.5 I need to get the seventh element of the array, so I need something like array [3.5*2-1]
well, why not just double what the user inputs, and then round that to an int?
www.artima.com/underthehood/floating.html
nothing to do with C -- please learn to read.
by assigning the result to an int?
you are not my sensei
well, I'd start with rint()
I wouldn't accept you as a student.
go and learn to read.
no one is asking
then stop spreading misinformation and lies.
no cross-reference with all appropriate information wrt. the question given as the answer to the question shall have been lied
what does that article you posted above have to do with C?
let's see ... is the answer 'nothing'?
well?
the good thing about lies and misinformation is that it's relativly easy to destroy it when you drag it into the light.
thanks
you are not drawing on a vacuum in anyone's head
what are you babbling about now?
the difference between knowledge and wisdom is not a restate
what are you babbling about now?
is array[rint(float-1)] a valid syntax in C?
no, because rint returns a double.
you'll need to cast that to an int
array[(int)rint(float)]?
yeah, C is not very good at arithmetic.
meaning?
automatic casting?
meaning that it has trouble with simple numeric operations such as addition and subtracting.
gotcha, thanks for your help
welcome
hello
is there any new project make sense?
Err... Abraham Lincoln?
too old
function names and struct members have diffrent scope in C? i can do struct foo { void (*exit)(int);}bar; bar.exit=exit; ?
Erm, yes...
thought so
no.
what now :P .. well i solved it diffrently anyways
they have the same scope as the struct.
but you can't have a function with the same name as a struct member ...
ok
well solved anyways
Hi !
re
int (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *); (from fuse.h)
is this good?
probably.
size_t (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *); ?
perhaps.
lol
ssize_t
the point being that read can return -1
if read is supposed to map to a posix-ish read, yes ssize_t.
Zhivago, ah probably, yeah
*
Zhivago, could there be any point in using int instead of ssize_t ?
uZhivago, could there be any point in using int instead of ssize_t ?/u
i'd say ssize_t would be more portable
they might not want to use a typedef?
Zhivago, hmm... dunno, but they are using size_t in the argument? why would they want this?
they were probably smoking crack, in the fine tradition of K&R.
hey lets say we have 1111 1000, what would it be in dec+
128+64+32+16+8 = 256
You have 2 lives left.
penguinFunk yes thats how i would read it but unfortionaly its -8
by two's complement
aa^way, but how do you know if its two's complement?
Kunalagon thats what i wonder
aa^way: http://xkcd.com/c169.html
aa^way: You need to specify what the value is treated as (signed, unsigned) and whether signed, which system is being used (one's complement, two's complement, sign-magnitude, etc.)
You need to add properly; the above would be 248 if unsigned 8bits.
xystic got any good link where i could learn?
how 248 ?
aa^way: 10^100.
Jafet what
Oh, sorry.
pow(10, 100);
128,64,32,16,8,4,2,1 in order?
That sums to 255, dinkhead.
You have one life left.
rofl!
http://dirtymicrobe.com/products/roflmao
hello, suppose i have this site http://www.utrace.de/?query=127.0.0.1 , but i want to make multiple queries so i can see multiple locations on the map, is there a trick like http://www.utrace.de/?query=127.0.0.1/?query=123.123 orsomething ?
penguinFunk you are right but you just did it wrong
I'd suggest that you use q1=...&q2=... etc
2^7+2^6+2^5+2^4+2^3+2^2+2^1+2^0
you can use q=...&q=..., but it might confuse the generating browser
got it now yeh, must have added 8 twice somewhere. it's early morning
lol
is it
ah you live in america
Zhivago, it shows only the last q
uk
I suggest you send them hate mail demanding this feature.
i have no idea whats different between america and uk
poor me
heh
what's yoru c question?
xezz i would make querys ilke query=127.0.0.1@[as splitter]53.2.23@o950.2389 and after you load GET query in PHP you just explode or splitt
aa^way: if you feel he needs help with php, join him in ##php.
twkm, helping is good thing mate
i appreciate man
thanx
hey wait ples how does system know whenever the bit is signed or not, lets say we have 11111111 , in unsigned it would be 255 and in signed it would be -1 ?
you told it.
128+64+32+16+8 = 256
viewed slightly differently, the system told the people that produced your implementation.
close. 248
aa^way: Black magic.
Jafet cool
aa^way: thing about it differently ... does the sign really matter for your cpu ?
you should know how the data in memory is represented before you try to use it for anything...
yes
there is a reason for the choice of two's complement system to represent signed value
aa^way: http://en.wikipedia.org/wiki/Two's_complement
im reading it right now
i suggest that you don't need to know the representation. in fact paying too much attention to it often hampers writing good c.
what function should i use to print to a file
the fprintf
or the fputc
either.
ok
Be aware of format string attackes when using fprintf.
that seems kinda funny directed at a person who calls themselves stacksmasher
Sounds like I've walked in at a fun moment
i expect he's already trying to be quite aware of them.
Hehe. A question like fprintf/fputc sounds kind of funny as well coming from someone who calls themselves stacksmasher
I'd be more worried about buffer overflow.
said overflow almost always intended to "smash the stack".
the evolution of a script kiddie tends to be 1) copy exploits written in C, run them randomly 2) attempt to change them to suit other needs 3) ask silly questions that could be found from an introductory C book 4) reach puberty and hopefully read the C book
'lo twkm
howdy IRBMe.
Another day of torrential rain here. You can't really tell it's summer -_-
Where IRBMe?
.uk?
You need to add properly; the above would be 248 if unsigned 8bits.
torrential rain here more often than not
Interestingly enough, most script kiddies know zilch about the underlying network beyond calls to a socket API, and never bother to learn.
rubberband, Scotland, where the weather is either rainy, drizzly or downpouring, with occassional torrential rain
naturally
i seem to have missed that one. sorry.
IRBMe, are you near edinburgh?
or glasgow?
aton` I live in the west end of Glasgow
the direction to greenock?
xystic, I think that applies not just to networks, but pretty much most things
IRBMe, can i pm, private matter
sure
It's a shame too, because I found TCP/IP very interesting: especially questioning certain aspects of it, even the things that seem elementary (e.g. why go-back-N is used for a sliding window, is smoothing of SRTT really necessary)
and not quite as far up as greenock - that's quite a way away from me, but that direction
*nods*
xystic, yes, and this is probably the first time I've found somebody who shares the same enthusiasm for transport and network protocols as I... or is it just TCP/IP ?
/Everything/ _above_ the physical and data-link layers. Up as high as QoS application-level protocols. I don't claim to have a superior understanding of most of them, just an exceedingly keen interest.
Ever looked in to some of the telephone system protocols such as ATM?
ditto
though I also have a keen interest in the datalink layer
It's interesting looking at how the telephone systems are being used for internet transfer (with basic modems, ISDN, DSL, ADSL etc.) and how, on the other hand, the internet systems are now being used for voice transfer (VOIP).
are many telephony people using SCTP?
It's completely backwards considering the internet protocols are poorly suited to voice, and the telephone systems are poorly suited for data, but they are perfectly suited for the opposite as their designs intended (data for internet, voice for telephone), yet the barriers are crossed so
much.. and it actually works
hello
hi Kartalon
http://rafb.net/p/P9T44e66.html (vars and somethings are written in spanish but i think it is easy to understand)
And what is it you need help with exactly? Compile error? Runtime error? Unexpected results? Ideas? Advice?
when i create a new node
it is not created
it seems like the list is always empty
What do you mean "it is not created" - how do you know? Is your output not what you expect?
but i don't get any error
output
What do you expect the output to be. What is the actual output?
at line 90 if lista is pointing to null
i get "Empty list" / "Lista vacia"
but even when i create a new node
Whatever you do with your call to insertar() in main() will not change the _value_ of 'lista', the local variable in main().
i get empty list
Figure out why insertar cannot change the value of 'lista' in main().
it may help you to be reminded that c is call by value.
what is the best thing when i want to search a string in a file and returning the previous value before that string??
Consult your C book on how objects are passed by value.
ok, thnx
a search function.
gonna sleep, gnight
but are there any that i can use
pre defined?
anyone know of some nice pastebin code ?
written in c. not off-hand.
twkm search like what? is there any function that does that
I'm not sure if anyone actually manages such collections, but you can start at http://rafb.net/paste.
can you be more specific?
you may find that insert(&list, value); offers inspiration.
i solved it, thnx ^^
i just returned lista through value
thanks
hi all
hi
is there an easy way to display a field of a certain struct variable with gdb?
when I try to cast my variable to the struct type, it says it can't find the struct's definition
yes.
twkm, interesting what is it?
that is a reasonable option
you cannot cast to a struct type.
thnx for your help ^^
print
Zhivago, I can't cast e.g. a void* to a struct*?
print
a struct is not a pointer
right, a pointer to struct is...
you said you had a struct, not a pointer to void. why would you lie to use like that?
err, us.
you must learn to be precise.
in that case, you have not defined the struct.
hmm, turns out you're right, because I made a typo... it does seem to work
thanks
bwt, does gdb ALWAYS indicate the correct source files when indicating a position in the execution?
for example:
no.
_libid_bind2 (selector=0x8085a04, receiver=0x80c54a4) at src/libid.c:646
I expected it to be in a different libid.c file...
the optimizer often seems to confuse it.
ah, ic... then how can I be sure which file it's actually using?
the recorded source file path is relative to the original compilation, not where you happen to be now.
twkm, ok, but in that case, I can be sure that the file it's using MUST have "src" in its real path?
at the time it was compiled, yes. now? perhaps not, though in that case gdb will likely whine.
chris vaite foder e leva nesse ganda cu
ndim e tu tambem
no.
ic... and I guess the same goes for line numbers? i.e. if the file has not changed since compilation, then the line number is certainly correct?
twkm, actually, is there a command which can extract from a .o file from which file it was compiled?
(otherwise, how does gdb extract it?)
yes.
twkm, which command is that?
optimization usually confuses gdb, so line numbers are the most suspect then.
chris if you have anything against my nick name i invite you to write a complait to the N.A.S.
hey
how do make a function with optional arguments in c?
how do i make a function with optional arguments in c?
Use your imagination.
If you don't have enough imagination, use C++.
haha ok
it's the same way the function main does, isn't it?
:P
make it variadic.
Oh noes stdarg molestation.
lol
of course that is usually much more hassle than having fixed arguments each of which can have a value that indicates it should not be considered.
Varargs are like threads and salt: Use sparingly.