N
Nick Keighley
Yes. In fact, the mere name "arnuld" conjurs up these impressions:
why? I just thought he couldn't spell
Yes. In fact, the mere name "arnuld" conjurs up these impressions:
if i have to criticize this code
this not compile here
Error E2188 b.c 36: Expression syntax in function print_table
Error E2451 b.c 36: Undefined symbol 'i' in function print_table
Error E2379 b.c 36: Statement missing ; in function print_table
Warning W8057 b.c 40: Parameter 'f' is never used in function print_table
Warning W8057 b.c 40: Parameter 'v' is never used in function print_table
Error E2188 b.c 46: Expression syntax in function get_value
Error E2451 b.c 46: Undefined symbol 'i' in function get_value
Error E2379 b.c 46: Statement missing ; in function get_value
Warning W8057 b.c 60: Parameter 'f' is never used in function get_value
Warning W8057 b.c 60: Parameter 'v' is never used in function get_value
*** 6 errors in Compile ***
even if use C99, there is always one error
__func__ has be __FUNC__ here
Vincenzo Mercuri said:int main(void){
const char* fields[] = {"OS",
"compiler",
"text-editor",
"mentor", NULL};
The fundamental approach is bad.
Make a skiplist and you can have a generic, ordered container. Or make
a hash table and you will have ultra-fast equality searching.
So the first part of the problem is to clearly specify the problem. Once
the problem is set in stone and all the parameters are clearly known,
then the rest of the system falls out all by itself.
Yes. In fact, the mere name "arnuld" conjurs up these impressions:
(1) not very experienced;
(2) willing and (unlike BC) able to learn;
(3) friendly, personable;
(4) doesn't suffer from Mohammed Ali Syndrome.
Well, the basic issue is that I receive data on some socket() which is
saved into a char array which looks like this:
Name: MY_PHONE
Core-ID: fb6b20fa-fabe-467c-8ec9-0edc1e335497
Machine-Hostname: gnu
Machine-IPv4: 192.168.0.202
Caller-Name: arnuld
Caller-ID: System_Programmer
Caller-Status: Call_Failed
Vincenzo Mercuri said:Il 23/06/2010 21.46, io_x ha scritto:
...is that a joke? Why this behaviour?
all your post in this argument, all togheter are a joke
*or* i not understand them
the OP problem
has to be seen using structs, array of structs, or table of structs
etc, or i not understand what OP whant
this is one useful example
#include<stdio.h>
#include<stdlib.h>
#include<stddef.h>
#define W while
#define R return
#define F for
#define P printf
#define B break
typedef struct{
char Os[128];
char editor[128];
char mentor[128];
}element;
// k==0 means search OS
// k==1 search editor
// k==2 means search mentor
// find from "start".."end" "whatSearch" in the array of struct "where"
int
findNext(element* where, int start, int end, char* whatSearch, int k)
{int i, j;
char *pc;
if(where==0||whatSearch==0||start>end)
R -1;
if(k==0) k=offsetof(element, Os);
else if(k==1) k=offsetof(element, editor);
else if(k==2) k=offsetof(element, mentor);
else R -1;
F(i=start; i<=end; ++i)
{F(j=0; ; ++j)
{if(where.Os[j+k]==whatSearch[j])
{if(whatSearch[j]==0)
R i;
}
else break;
}
}
R -1;
}
int findNextOs (element* w, int start, int end, char* search)
{R findNext(w, start, end, search, 0);}
int findNextEditor(element* w, int start, int end, char* search)
{R findNext(w, start, end, search, 1);}
int findNextMentor(element* w, int start, int end, char* search)
{R findNext(w, start, end, search, 2);}
int insert(element* w, int pos, element* v)
{int i;
if(w==0||v==0) R 0;
F(i=0; i<(int) sizeof(element); ++i)
w[pos].Os=(*v).Os;
R 1;
}
int def(element* v, char* Os, char* editor, char* mentor)
{int i;
if(v==0||Os==0||editor==0||mentor==0) R 0;
i=0;
W(1){v->Os=Os;
if(Os==0) B;
if(i>=127) R 0;
++i;
}
i=0;
W(1){v->editor=editor;
if(editor==0) B;
if(i>=127) R 0;
++i;
}
i=0;
W(1){v->mentor=mentor;
if(mentor==0) B;
if(i>=127) R 0;
++i;
}
R 1;
}
int showElement(element* t)
{if(t==0||t->Os==0||t->editor==0||t->mentor==0)
R 0;
P("Os : %s\n", t->Os);
P("editor: %s\n", t->editor);
P("mentor: %s\n", t->mentor);
R 1;
}
int showTable(element* t, int num)
{int i;
if(t==0) R 0;
F(i=0; i<num; ++i)
{P("Element %d\n", i);
showElement(t+i);
P("\n");
}
R 1;
}
int azzeraTable(element* where, int number)
{int i;
if(where==0) R 0;
F(i=0; i<number; ++i){where.Os [0]=0;
where.editor[0]=0;
where.mentor[0]=0;
}
R 1;
}
int main(void)
{int i;
char arr[512], *p1, *p2, *p3;
element table[1024]; // one general table of 1024 elements
azzeraTable(table, 1024);
F(i=0; i<512; ++i) arr=0;
p1=arr+ 0;
p2=arr+128;
p3=arr+256;
F(i=0; i<100; ++i)
{sprintf(p1, "%.91s%d", "XOs", i);
sprintf(p2, "%.91s%d", "Xeditor", i);
sprintf(p3, "%.91s%d", "Xmentor", i);
def(table+i, p1, p2, p3);
}
def(table+203, "XOs23", "Xeditor23", "Xmentor23");
showTable(table, 100);
showElement(table+203);
F(i=0;
{i=findNextOs(table, i, 1023, "XOs23");
if(i!=-1) P("Find XOs23 in struct %d\n", i);
else B;
++i;
}
F(i=0;
{i=findNextEditor(table, i, 1023, "Xeditor23");
if(i!=-1) P("Find Xeditor23 in struct %d\n", i);
else B;
++i;
}
F(i=0;
{i=findNextMentor(table, i, 1023, "Xmentor23");
if(i!=-1) P("Find XMentor23 in struct %d\n", i);
else B;
++i;
}
R 0;
}
what beutiful peace of code
I think we all appreciate to get fun with code sometimes, but why
this try to prove yourself as some kind of a bizarre genius?
all we are genius because each of we can write something nobody
can write
If this is your intent, you are unlikely able to do it.
were i'm unlike
I think there are some people here who would really have
enough skills to do better.
yes i know it too, but in this tread they not write well, i not understand
If they only wanted.
yes
So, even as a joke it is not well-made. We are all free to
use the style we prefer,
so i use my
yes my error could be this, if each of us use his/her style
it is possible no one understand what the other write
but i'm not for this interpretation, i can read well all code
is here, even the strange one, if think about it 10 minuts
and debug something
but i think sometimes you persist
in showing off a bit of lack of regards about the readers.
yes, but i'm not OT, the code above is 100% standard C
so i could post it
but some day i will be tired, and will go away
Trying to be clear and showing our ideas in an intelligible manner
would be desirable by the most (hopefully).And about your italian words in your code...I am italian too,
i find only one half italian word in that code "azzeraTable".
you find more thant one word?
but i think it is easily understandable in english
exist "zero" too
and i think i have to recall you that english is the lingua franca
in programming, and we should use it when talking to people overseas,
i'm not agree, something can be written in own language too
so we can all understand, appreciate and share new ideas.
Please don't continue with this self-destructive behaviour,
this is not self-destructive behaviour
and try to let people appreciate your true abilities.
thanks for this line
and i think i have to recall you that english is the lingua franca
in programming, and we should use it when talking to people overseas, so
On Jun 23, 11:55 am, Vincenzo Mercuri<[email protected]>
wrote:
<snip>having identifiers and comments in one's own language is helpful, but
I'd rather read well-structured code where the names are (to me)
unrelated to purpose than the all-too-common code where the names
mislead.
BruceS said:I almost added a closing little joke, but decided against, as I've
previously overestimated clc regulars' humor quotient.
Which in turn should have also been....
Forget it. I'm going back to talking to myself.
Ike said:Vincenzo Mercuri said:int main(void){
const char* fields[] = {"OS",
"compiler",
"text-editor",
"mentor", NULL};
Please forgive me for the digression, but here is a brace style issue
that has often puzzled me.
Some people write (A)
header
{
body
}
Other people write (B)
header {
body
}
The nice thing about (A) is that the braces line up neatly.
The nice thing about (B) is that it saves vertical space, compared to (A).
But this (C)
header {
body
}
seems to be the worst of both worlds; neither do the braces line up,
nor does it save vertical space.
What would be the rationale for brace style (C) ?
Vincenzo said:Ike said:Vincenzo Mercuri said:int main(void){
const char* fields[] = {"OS",
"compiler",
"text-editor",
"mentor", NULL};
Please forgive me for the digression, but here is a brace style issue
that has often puzzled me.
Some people write (A)
header
{
body
}
Other people write (B)
header {
body
}
The nice thing about (A) is that the braces line up neatly.
The nice thing about (B) is that it saves vertical space, compared to
(A).
But this (C)
header {
body
}
seems to be the worst of both worlds; neither do the braces line up,
nor does it save vertical space.
What would be the rationale for brace style (C) ?
Ok, i think i have to better understand how thunderbird
and seamonkey work, because i have some issues when i copy
and paste my code from Gedit or other editors.
In my editor formatting looks like the (B) option.
i'll do my best to fix formatting issues.
I may agree on this.
Well, the basic issue is that I receive data on some socket() which is
saved into a char array which looks like this:
Name: MY_PHONE
Core-ID: fb6b20fa-fabe-467c-8ec9-0edc1e335497
Machine-Hostname: gnu
Machine-IPv4: 192.168.0.202
Caller-Name: arnuld
Caller-ID: System_Programmer
Caller-Status: Call_Failed
I have to find some value in that array belonging to a key, just once,
well, may be twice in a rare situation. I did not talk about socket fd
here as its not the place to talk about those things. So I have find the
the values in a char array belonging to one or two unique key. This is
all I have to do.
But Dan, I did get some programming ideas from you (loved reading
them )
Il 24/06/2010 15.10, arnuld ha scritto:
<snip>have the string received from the socket, in the same form
as *arnuld* gave us (I will just insert some random \r at the
end of a line or a white space between words and comma):
[...]
I almost added a closing little joke, but decided against, as I've
previously overestimated clc regulars' humor quotient.
Are you calling us humorless? That's not funny!
(I don't really need a smiley here, do I?)
I hope I made the reasons of my reaction clear.
[...]
I almost added a closing little joke, but decided against, as I've
previously overestimated clc regulars' humor quotient.
Are you calling us humorless? That's not funny!
I guess we'll just have to see.
(I don't really need a smiley here, do I?)
Yes. Yes, you do.
I generally avoid smileys, but something just occurred to me.
Wouldn't it be a wonderful coding style, both improving readability
and impressing readers with one's skills, to replace the various
keywords and punctuation marks in C (apparently preferred by stuck-in-
the-mud fuddy duddies) with emoticons? After all, *this* is the real
purpose of the preprocessor. The only questions left are (1) what are
the most appropriate smileys to use to replace "if", "double", etc.,
and (2) how to correctly write the macros for this.
[...]
I almost added a closing little joke, but decided against, as I've
previously overestimated clc regulars' humor quotient.
Are you calling us humorless? That's not funny!I guess we'll just have to see.Yes. Yes, you do.I generally avoid smileys, but something just occurred to me.
Wouldn't it be a wonderful coding style, both improving readability
and impressing readers with one's skills, to replace the various
keywords and punctuation marks in C (apparently preferred by stuck-in-
the-mud fuddy duddies) with emoticons? After all, *this* is the real
purpose of the preprocessor. The only questions left are (1) what are
the most appropriate smileys to use to replace "if", "double", etc.,
and (2) how to correctly write the macros for this.
Oh God, please revoke this message quickly. Somebody *will* do this.
There is already a standard for including emoticons to indicate IP packet
"mood":
http://tools.ietf.org/rfc/rfc5841.txt
and a programing language in LOLCAT lingo:
http://lolcode.com/specs/1.2
Yes, somebody will do this and *I* will end up having to maintain the code.
Joke indeed. Ha!
<snip>#define NUMBER_OF_LINES 100
/* by 'field' I mean a word like "Name" in "Name: MY_PHONE"
or "Machine-Hostname" in "Machine-Hostname: gnu" */
#define NUMBER_OF_FIELDS 100
/* by 'value' I mean a word like "MY_PHONE" in "Name: MY_PHONE"
or... */
#define NUMBER_OF_VALUES 100
<snip>char* lines[NUMBER_OF_LINES] = { NULL };
>
char* fields[NUMBER_OF_FIELDS] = { NULL };
char* values[NUMBER_OF_VALUES] = { NULL };
for(int i = 1; ( lines = strtok(NULL, END_OF_LINE) ); i++);
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.