void BytesTest()
{
bytes_load("some.txt");
while(bytes_cursor<bytes_size)
{
int value = bytes_dig_int_from_cursor();
if(bytes_cursor>bytes_size) break;
printf("\n %d", value);
}
}
fir wrote:
void BytesTest()
{
bytes_load("some.txt");
while(bytes_cursor<bytes_size)
{
int value = bytes_dig_int_from_cursor();
if(bytes_cursor>bytes_size) break;
printf("\n %d", value);
}
}
as to this part i was thinking that using the bytes_cursor
(or how to call it better) would be good idea and would simplify
the usage of it but this loop is also overcomp0-lex so im not sure
if to using sorta global variable (like "none") wouldnt be better here
thsi is odlschool idea and i dont seen its used today but here it
is just simple
for(;;)
{
int value = dig_int();
if(none) break;
}
it seems that this group likes such kind of topics, so
here you got
improve that function - i wrote it in quick and feel tired so i
dont want to improve it as for now
i got "list" of bytes (by list i mean pointer to ram area of
elements - loke reallocked by reallock, by aray i would rather
aybe name fully static array and heap seeds are more like lists
especially if you use them as lists - and got methods like "add"
(remove etc)
unsigned char* bytes = NULL;
int bytes_size = 0;
int bytes_allocked = 0;
int bytes_cursor = 0;
i wint to write a function DigInt that "digs" one int form that
list and returns its, then the "cursor" is set after that and you
can call it again untill all ints are "digged"
[code]
fir <fir@grunge.pl> writes:
it seems that this group likes such kind of topics, so
here you got
improve that function - i wrote it in quick and feel tired so i
dont want to improve it as for now
i got "list" of bytes (by list i mean pointer to ram area of
elements - loke reallocked by reallock, by aray i would rather
aybe name fully static array and heap seeds are more like lists
especially if you use them as lists - and got methods like "add"
(remove etc)
unsigned char* bytes = NULL;
int bytes_size = 0;
int bytes_allocked = 0;
int bytes_cursor = 0;
i wint to write a function DigInt that "digs" one int form that
list and returns its, then the "cursor" is set after that and you
can call it again untill all ints are "digged"
[code]
I usually prefer (and recommend) writing code that doesn't make
use of global state, as for example:
long
next_value( char *s0, char **next_s ){
char *s = s0 + strcspn( s0, "0123456789" );
return
!*s
? *next_s = s0, 0
: strtol( s - (s!=s0 && s[-1]=='-'), next_s, 10 );
}
Retrieving and processing successive values can be done using
this function by means of a simple for() loop, as illustrated by
the code below:
void
print_longs( char *s ){
long v;
printf( " input: %s\n", s );
for( char *next; v = next_value( s, &next ), s != next; s = next ){
printf( " value: %12ld\n", v );
}
printf( "\n" );
}
Note that the local variable 'next' here takes the place of a
cursor for the next input.
Tim Rentsch wrote:
fir <fir@grunge.pl> writes:
it seems that this group likes such kind of topics, so
here you got
improve that function - i wrote it in quick and feel tired so i
dont want to improve it as for now
i got "list" of bytes (by list i mean pointer to ram area of
elements - loke reallocked by reallock, by aray i would rather
aybe name fully static array and heap seeds are more like lists
especially if you use them as lists - and got methods like "add"
(remove etc)
unsigned char* bytes = NULL;
int bytes_size = 0;
int bytes_allocked = 0;
int bytes_cursor = 0;
i wint to write a function DigInt that "digs" one int form that
list and returns its, then the "cursor" is set after that and you
can call it again untill all ints are "digged"
[code]
I usually prefer (and recommend) writing code that doesn't make
use of global state, as for example:
long
next_value( char *s0, char **next_s ){
char *s = s0 + strcspn( s0, "0123456789" );
return
!*s
? *next_s = s0, 0
: strtol( s - (s!=s0 && s[-1]=='-'), next_s, 10 );
}
Retrieving and processing successive values can be done using
this function by means of a simple for() loop, as illustrated by
the code below:
void
print_longs( char *s ){
long v;
printf( " input: %s\n", s );
for( char *next; v = next_value( s, &next ), s != next; s = next ){ >> printf( " value: %12ld\n", v );
}
printf( "\n" );
}
Note that the local variable 'next' here takes the place of a
cursor for the next input.
well ok..this is kinda tricky style but thats a matter of personal
style i prefer more "strightforward" long descriptive names etc
two remarks here
1) people shoudl avoid imo talking a word "global" becouse in
normal desctop computing at least those variables are not global
but typically belong to library (dll) so they are library
scope/module scope not global (this is my own remark as i noticed
this) (thay may also be exe scope but thsi is also module scope
[...]
Sysop: | Tetrazocine |
---|---|
Location: | Melbourne, VIC, Australia |
Users: | 7 |
Nodes: | 8 (0 / 8) |
Uptime: | 129:01:21 |
Calls: | 46 |
Files: | 21,492 |
Messages: | 64,847 |