Newbie question - displaying trivia questions at random

A

av

av, get your damn attributions correct! I didn't
this crap!!!


goose,

lets see

"On 7 Aug 2006 04:10:47 -0700, goose wrote:

this run here too
//

int P(char* , ... ); /* print console */

#define F for
#define R return
#define W while
#define G goto


#define _EoF (1)
#define _EoM (2)
#define _NuL (4)
#define _UnG (8)

int getline_state=0, getline_len=0;
"

this is the first part of post
the attributction are right because "goose level" is ">"

and there there is no ">"
all of that is mine
 
B

Barry Schwarz

it is not "realloc" it is "realloc_m"; so if i have realloc_m is all
ok

Only if you have a prototype in scope at the point the function is
called.


Remove del for email
 
M

Mark McIntyre

lets see

"On 7 Aug 2006 04:10:47 -0700, goose wrote:

this run here too
// ....
"

this is the first part of post
the attributction are right because "goose level" is ">"

and there there is no ">"
all of that is mine

This is true, but its normal to actually quiote some text if you are
putting in the attribution line. Since you quoted nothing, its
naturaly that people would be confused. Why not post properly?

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
M

Mark McIntyre

it is not "realloc" it is "realloc_m"; so if i have realloc_m is all
ok

there's no such function as realloc_m
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
M

Mark McIntyre

On 7 Aug 2006 04:10:47 -0700, goose wrote:

Nothing that you quoted. If you don't propose to quote anyone, don't
include an attribution.
int P(char* , ... ); /* print console */

#define F for
#define R return
#define W while
#define G goto

Don't use pointlessly obfuscating macros.
Rest of code snipped as unreadable.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
K

Keith Thompson

Mark McIntyre said:
Nothing that you quoted. If you don't propose to quote anyone, don't
include an attribution.

Agreed -- but it's an easy enough mistake to make.
 
K

Keith Thompson

Mark McIntyre said:
[...]
it is not "realloc" it is "realloc_m"; so if i have realloc_m is all
ok

there's no such function as realloc_m

There is if you define it yourself. Of course if you do that, we
can't know what it does without seeing the definition, or at least
some documentation.
 
A

av

Mark McIntyre said:
[...]
it is not "realloc" it is "realloc_m"; so if i have realloc_m is all
ok

there's no such function as realloc_m

There is if you define it yourself. Of course if you do that, we
can't know what it does without seeing the definition, or at least
some documentation.

it should be the same of stdlib.h "realloc()"
 
P

pete

av said:
Mark McIntyre said:
[...]
it is not "realloc" it is "realloc_m";
so if i have realloc_m is all ok

there's no such function as realloc_m

There is if you define it yourself. Of course if you do that, we
can't know what it does without seeing the definition, or at least
some documentation.

it should be the same of stdlib.h "realloc()"

All of that, makes no sense.
If realloc_m is the same as realloc,
then it can't make any difference
whether you use one or the other.
 
G

goose

pete said:
av said:
[...]
it is not "realloc" it is "realloc_m";
so if i have realloc_m is all ok

there's no such function as realloc_m

There is if you define it yourself. Of course if you do that, we
can't know what it does without seeing the definition, or at least
some documentation.

it should be the same of stdlib.h "realloc()"

All of that, makes no sense.
If realloc_m is the same as realloc,
then it can't make any difference
whether you use one or the other.

None of his (av) code makes any sense. He proposed
to replace my (relatively) clear 88 line solution
with his horribly obfuscated 145 line solution.

It's ironic that even with reliance on unpresent
non-std functions and pointless macro-ition of code,
it's still longer than a properly written ansi
routine of equivalent functionality.

There's a lesson in there somewhere ...

goose,
 
A

av

All of that, makes no sense.
If realloc_m is the same as realloc,
then it can't make any difference
whether you use one or the other.

it seems realloc in all, but with that realloc_m there is another
routine that can see if there are memory bound error or memory leaks
 
A

av

None of his (av) code makes any sense. He proposed
to replace my (relatively) clear 88 line solution

The lines of my version below, is 60 lines, and all is easier
with his horribly obfuscated 145 line solution.

It's ironic that even with reliance on unpresent
non-std functions and pointless macro-ition of code,

Your version is good and portable, but not check for failure
in positioning in the file
it's still longer than a properly written ansi
routine of equivalent functionality.

it is not ansi but i reduce complexity of all
(i hope that the arrive point will not be Visual Basic)
this means fast and minor possibility for doing errors.
then for porting my version (assume the same x86 cpu type)
i have to rewrite only the OS calls in the assembly source
and use some C++ compiler, and Nasm assembler
There's a lesson in there somewhere ...

i show you the way :)
"reduce instruction size in the paper"
--------------------------------------
#include "winb.h"

static char **text =0;
static int num_items =0;

int resize(void)
{static int w=0;
char **t;
w = (w==0? 14: 2*w+2);
t=(char**) realloc_m(text,(w+2)*(sizeof *t));
if(t==0) R 0;
text=t;
R w;
}

static char* trivia(int index)
{if(text) R text[index%num_items];
else R "Null ";
}

#define DELIMITATORE "%\x0D\n"

static int load_data(istream& in)
{int i, w;
// ///////////////
/* find the first record */
i=fseek_m(in.f, 0, SEEK_SET);
if(i!=0) R 0;
/* read in each piece of trivia text */
F( i=0, w=0; ;)
{label:
if(i>=w)
{w=resize();
if(w<=0){P("Memoria insufficiente\n"); break;}
else G label;
}
text=in.getline(0, DELIMITATORE); // DILIM==%\13\n
if(text==0) {getline_error(); break; }
++i;
if(getline_state&1) break;
}
num_items=i;
R i;
}

char *name="trivia.txt";

int main(void)
{int i;
istream triviatxt(name);

if(triviatxt==0)
{P("Can not open %s file\x0D\n", name); R 1;}
if(load_data(triviatxt)==0)
{P("Can not load data from %s file\x0D\n", name );
// i'm forgetting something?
R 1;
}
P("Number of items = %i\x0D\n", num_items);
F( i=0; i<num_items; ++i)
P("Trivia #%i:\x0D\n%s\x0D\n", i, trivia(i));
exit_m(0); // exit_m here free all dinamic memory
// (returned from malloc_m )
// close all file and call "exit(0);"
// that free
// all global object that compiler has
// in the prog
}
 
G

goose

av said:
The lines of my version below, is 60 lines, and all is easier

No, it isn't.
Your version is good and portable, but not check for failure
in positioning in the file

I'm sure it did.
it is not ansi but i reduce complexity of all

No you don't, you have increased complexity.
(i hope that the arrive point will not be Visual Basic)

It's already worse than that, believe me.
this means fast and minor possibility for doing errors.
then for porting my version (assume the same x86 cpu type)
i have to rewrite only the OS calls in the assembly source
and use some C++ compiler, and Nasm assembler


i show you the way :)

Your code doesn't work anyway; why are posting
broken obfuscated code? Were you in an accident
recently? Did you get some minor damage to the
head?

It's easy to write code if it doesn't have to work.


<snipped broken code>

goose,
I'd plonk you if I could.
 
F

Flash Gordon

av said:
i show you the way :)
"reduce instruction size in the paper"

<snip rubbish code>

The only things you are showing are your ineptitude as a programmer and
how not to write code. Even with gcc in its default mode I get:

markg@brenda:~$ gcc t.c
t.c:1:18: error: winb.h: No such file or directory
t.c: In function ‘resize’:
t.c:11: error: ‘R’ undeclared (first use in this function)
t.c:11: error: (Each undeclared identifier is reported only once
t.c:11: error: for each function it appears in.)
t.c:11: error: syntax error before numeric constant
t.c:13: error: syntax error before ‘w’
t.c: In function ‘trivia’:
t.c:17: error: ‘R’ undeclared (first use in this function)
t.c:17: error: syntax error before ‘text’
t.c: At top level:
t.c:23: error: syntax error before ‘&’ token
t.c: In function ‘load_data’:
t.c:27: error: ‘in’ undeclared (first use in this function)
t.c:27: error: ‘SEEK_SET’ undeclared (first use in this function)
t.c:28: error: ‘R’ undeclared (first use in this function)
t.c:28: error: syntax error before numeric constant
t.c:30: error: syntax error before ‘;’ token
t.c:34: error: break statement not within loop or switch
t.c:35: error: ‘G’ undeclared (first use in this function)
t.c:35: error: syntax error before ‘label’
t.c: At top level:
t.c:37: error: ‘i’ undeclared here (not in a function)
t.c:37: error: ‘in’ undeclared here (not in a function)
t.c:37: warning: data definition has no type or storage class
t.c:38: error: syntax error before ‘if’
t.c:42: error: redefinition of ‘num_items’
t.c:4: error: previous definition of ‘num_items’ was here
t.c:42: warning: data definition has no type or storage class
t.c:43: error: syntax error before ‘i’
t.c:43: warning: data definition has no type or storage class
t.c: In function ‘main’:
t.c:50: error: ‘istream’ undeclared (first use in this function)
t.c:50: error: syntax error before ‘triviatxt’
t.c:52: error: ‘triviatxt’ undeclared (first use in this function)
t.c:53: error: ‘R’ undeclared (first use in this function)
t.c:53: error: syntax error before numeric constant
t.c:57: error: syntax error before numeric constant
t.c:60: error: syntax error before ‘;’ token
t.c:60: error: syntax error before ‘)’ token
markg@brenda:~$

I also spotted you still have a number of stupidities that have already
been pointed out to you.
 
A

av

No, it isn't.

yes it is
I'm sure it did.

for fseek(), fgetpos() and for fsetpos() you didn't use the return
values
No you don't, you have increased complexity.

i not agree. i should reduce and order complexity.

yes i can write all wrong, but all you make errors too
It's already worse than that, believe me.

i hope not
Your code doesn't work anyway;

here it run all very well "anyway". if i see something that not goes
well i debug, rewrite and in an hour is all ok (from OS call, to each
routine that i call is all "rewritten" by me)
why are posting
broken obfuscated code?

because i like to see my post in usenet for say
"how good those post appear ... how they are good :)-O "
 
A

av

it seems ok
The only things you are showing are your ineptitude as a programmer and
how not to write code. Even with gcc in its default mode I get:

i prefer your "ineptitude" and all run well, to other approvation and
buggy programs
i forgot to say there is an header all you not have and 2 object files
to link with it
something like
gcc t.cpp file1.obj file2.obj

but this seems trivial to understand until i say nothing.
i surprise myself a programmer of your size don't see it soon :)
markg@brenda:~$ gcc t.c
t.c:1:18: error: winb.h: No such file or directory
t.c: In function ‘resize’:
t.c:11: error: ‘R’ undeclared (first use in this function)

macro "R" is in the header i include in all my source code
I also spotted you still have a number of stupidities that have already
been pointed out to you.

thank you if you point out "stupidities" but this time you are wrong
 
H

Herbert Rosenau

The lines of my version below, is 60 lines, and all is easier


Your version is good and portable, but not check for failure
in positioning in the file


it is not ansi but i reduce complexity of all
(i hope that the arrive point will not be Visual Basic)
this means fast and minor possibility for doing errors.
then for porting my version (assume the same x86 cpu type)
i have to rewrite only the OS calls in the assembly source
and use some C++ compiler, and Nasm assembler

It is complete crap because nobody can understund that.

You delivers a good lession how NOT to program.

You are even 100% off topic because you says yourself thst it is NOT C
and tries not eve3n to be.
i show you the way :)
"reduce instruction size in the paper"

--------------------------------------
#include "winb.h"

static char **text =0;
static int num_items =0;

int resize(void)
{static int w=0;
char **t;
w = (w==0? 14: 2*w+2);
t=(char**) realloc_m(text,(w+2)*(sizeof *t));

Undefined behavior.

Only dumbass casts result of a function returning pointer to void.
if(t==0) R 0;
text=t;
R w;
}

static char* trivia(int index)
{if(text) R text[index%num_items];

Will not compile because syntax error.
else R "Null ";

another syntax error
}

#define DELIMITATORE "%\x0D\n"

static int load_data(istream& in)
{int i, w;
// ///////////////
/* find the first record */
i=fseek_m(in.f, 0, SEEK_SET);
if(i!=0) R 0;
/* read in each piece of trivia text */
F( i=0, w=0; ;)
{label:
if(i>=w)
{w=resize();
if(w<=0){P("Memoria insufficiente\n"); break;}
else G label;
}
text=in.getline(0, DELIMITATORE); // DILIM==%\13\n
if(text==0) {getline_error(); break; }
++i;
if(getline_state&1) break;
}
num_items=i;
R i;
}

char *name="trivia.txt";

int main(void)
{int i;
istream triviatxt(name);

if(triviatxt==0)
{P("Can not open %s file\x0D\n", name); R 1;}
if(load_data(triviatxt)==0)
{P("Can not load data from %s file\x0D\n", name );
// i'm forgetting something?
R 1;
}
P("Number of items = %i\x0D\n", num_items);
F( i=0; i<num_items; ++i)
P("Trivia #%i:\x0D\n%s\x0D\n", i, trivia(i));
exit_m(0); // exit_m here free all dinamic memory
// (returned from malloc_m )
// close all file and call "exit(0);"
// that free
// all global object that compiler has
// in the prog
}


Horrible code because indents are unspecified.

When you need space ask me. I send you some millions for free!

undefined macros makes it impossible to compile the crap.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
F

Flash Gordon

av said:
it seems ok


i prefer your "ineptitude" and all run well, to other approvation and
buggy programs
i forgot to say there is an header all you not have and 2 object files
to link with it
something like
gcc t.cpp file1.obj file2.obj

but this seems trivial to understand until i say nothing.
i surprise myself a programmer of your size don't see it soon :)

I am fully aware of how to handle far larger projects than this with
multiple different compilers.
macro "R" is in the header i include in all my source code

So? No one else has that header.
thank you if you point out "stupidities" but this time you are wrong

No, I am correct. The source you have provided does not work as given.
Since no one else has that header file and your source depends on it
there is absolutely point in providing the code unless it is to provoke
complaints.

Also, as you have been told before, those single character macros to use
standard C keywords and function just obfusticate your code.

Since you seem to be congenitally incapable of writing code that any one
else considers sane about the only responses you will see from me from
now on will be when I consider there to be a risk that some newbie might
consider your code worth examining. Then I will only do sufficient to
show why it should be ignored.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top