 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ben Pfaff Guest
|
Posted: Tue Jun 24, 2003 5:15 am Post subject: Re: linked list |
|
|
Ryan Molden <none (AT) fake (DOT) com> writes:
| Quote: | On Mon, 23 Jun 2003 02:26:58 +0100, Richard Heathfield
[email]binary (AT) eton (DOT) powernet.co.uk[/email]> wrote:
I guess you could always check the Rationale:
http://www.lysator.liu.se/c/rat/d11.html#4-11-2-4
Thank you much, will do. I noticed this is the rationale for C89,
am I to take it the idea behind most standard lib functions and such
as discussed here has not changed in C99?
|
There are few, if any, incompatible changes from the C89 library
to the C99 library. strncpy() in particular has not changed.
| Quote: | I know they no longer do the rationale.
|
I must be hallucinating then.
http://std.dkuug.dk/JTC1/SC22/WG14/www/docs/n897.pdf
--
"Some programming practices beg for errors;
this one is like calling an 800 number
and having errors delivered to your door."
--Steve McConnell
|
|
| Back to top |
|
 |
Ryan Molden Guest
|
Posted: Tue Jun 24, 2003 7:19 am Post subject: Re: linked list |
|
|
On 23 Jun 2003 22:15:44 -0700, Ben Pfaff <blp (AT) cs (DOT) stanford.edu> wrote:
Wow, thanks, I had heard from a source I previously held to be
reliable that they had stopped doing the rationale, but I see now he
was a lying sack of s&*t ;)
Ryan Molden
-------------------------[ Student ]----------------------------------
University Of Washington
Dept. of Computer Science and Engineering
----------------------------------------------------------------------------
|
|
| Back to top |
|
 |
Dave Thompson Guest
|
Posted: Fri Jul 04, 2003 12:21 am Post subject: Re: linked list |
|
|
On 23 Jun 2003 22:15:44 -0700, Ben Pfaff <blp (AT) cs (DOT) stanford.edu> wrote:
Or n937, the latest AFAICT.
- David.Thompson1 at worldnet.att.net
|
|
| Back to top |
|
 |
Vladimir S. Oka Guest
|
Posted: Sat Jan 28, 2006 10:04 am Post subject: Re: reda4win released |
|
|
pablo reda wrote:
| Quote: | mi program is plain c, gcc compiled with devcpp and SDL library
|
But the /language/ you implemented in C isn't so it's not topical here.
As Keith said, your /implementation/ however may be topical.
Cheers
Vladimir
PS
Also, please quote what and who you're replying to:
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
--
Trying to establish voice contact ... please _yell_ into keyboard. |
|
| Back to top |
|
 |
Alex Fraser Guest
|
Posted: Sat Jan 28, 2006 3:05 pm Post subject: Re: Bit-fields and integral promotion/UACs |
|
|
"CBFalconer" <cbfalconer (AT) yahoo (DOT) com> wrote in message
news:43DAEDF4.5C2B41AE (AT) yahoo (DOT) com...
| Quote: | Alex Fraser wrote:
"CBFalconer" <cbfalconer (AT) yahoo (DOT) com> wrote in message
[snip]
Anyway I have added that (tautened) code back below:
#include <stdio.h
int main(void) {
struct test {
unsigned int x : 1;
} test;
test.x = 1;
printf("%lu\n", (unsigned long) ((unsigned int) test.x << 31));
return 0;
}
The OP stated 32-bit ints, so the value of "(unsinged int) text.x
31" can be represented in the result type, unsigned int.
No it can't by that code.
|
Pardon?
| Quote: | And why did you remove the corrected code that didn't care how many bits
were in an int?
|
Because it is irrelevant to the behaviour of the code above when the number
of bits in an int is known, which is the reason for this thread.
Alex |
|
| Back to top |
|
 |
Marco Guest
|
Posted: Sat Jan 28, 2006 3:06 pm Post subject: Re: reda4win released |
|
|
post your new language on: comp.lang.misc
not in comp.lang.c
(instead of just telling people what not to do) |
|
| Back to top |
|
 |
Joe Wright Guest
|
Posted: Sat Jan 28, 2006 4:01 pm Post subject: Re: Second Highest number in an array |
|
|
CBFalconer wrote:
| Quote: | Joe Wright wrote:
Jaspreet wrote:
I was working on some database application and had this small
task of getting the second highes marks in a class. I was able
to do that using subqueries.
Just thinking what is a good way of getting second highest
value in an integer array. One method I know of is to make the
1st pass through the array and find the highest number. In the
second pass we can find the highest number which is less than
the number we obtained in the 1st pass.
However there has to be a better and more efficient way of
doing this. Please just let me know some hints and I would try
it on my own in C.
#include <stdio.h
int main(void) {
int pri, sec, i, v;
int arr[] = {4,10,3,8,6,7,2,7,9,2,0};
pri = sec = 0;
for (i = 0; arr[i]; ++i) {
v = arr[i];
if (v > pri) sec = pri, pri = v;
if (v > sec && v < pri) sec = v;
}
printf("pri is %d, sec is %d\n", pri, sec);
return 0;
}
One trip through the array.
On the principle of "look to the innermost loop", why the extra
test?
for (i = 0, v = arr[0]; v; v = arr[++i])
if (v > pri) {sec = pri; pri = v;}
else if (v > sec) sec = v;
and we can do even better with a pointer.
int *p;
...
for (p = arr, v = *p++; v; v = *p++)
... same ...
I take your first argument. The for () can be simpler. Cute block. |
for (i = 0; (v = arr[i]); ++i) {
if (v > pri) sec = pri, pri = v;
else if (v > sec) sec = v;
}
The pointer treatment can be simpler too..
for (p = arr; (v = *p++)
... same ...
--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein --- |
|
| Back to top |
|
 |
pablo reda Guest
|
Posted: Sat Jan 28, 2006 4:01 pm Post subject: Re: reda4win released |
|
|
Thanks Vladimir.
just download the file, unzip and try the .exe file
all the .txt file are source code.
try modify MAIN.TXT and reda4.exe again...ready
I still in developer stage, I release the code when I have a stable
wordset.
Is not my purpose disturbing, only make some friend to talk
Thanks Pablo |
|
| Back to top |
|
 |
Kenny McCormack Guest
|
Posted: Sat Jan 28, 2006 5:00 pm Post subject: Re: How to find the depencies among files in a project |
|
|
In article <slrndtknjo.2qhf.random832 (AT) random (DOT) yi.org>,
Jordan Abel <random832 (AT) gmail (DOT) com> wrote:
| Quote: | On 2006-01-27, Kenny McCormack <gazelle (AT) yin (DOT) interaccess.com> wrote:
In article <ti4oa3xngu.ln2 (AT) news (DOT) flash-gordon.me.uk>,
To make this more clear, to a googler, it doesn't make any sense to "quote"
(whatever the heck that is...), in fact, to do so would be absurd, when all
the rest of the articles in the thread are right there in front of their
faces (just as clear as the trunk on that mouse, er, elephant). And no
amount of verbiage from us is going to convince them not to believe what
they see. The point is you can *never* convince someone that what they see
isn't reality. The only way you can address the problem is to help them
fix their eyesight (or help them remove their funny glasses).
Except that quoting is the norm on most web forums also, so it makes
more sense that the reason is the fact that the "reply" button doesn't
quote, or that the user is just an idiot
(i know, i know, don't feed the troll - the problem with that for me is
that i think that Kenny really does honestly believe what he is saying)
|
Yes, I do honestly believe it. It is called "trolling on the square".
To address your issue: It is *not* the norm, in the real world, as it
exists in 2006. It may be the norm on the "web forums" that *you*
frequent, since you appear to be reasonably technically savvy and the
forums that *you* frequent probably are reasonably technically
sophisticated and are thus probably governed by the same ethos as was
common in the Usenet of old - the one that we all grew up with, but is,
alas, no more.
Note also that it varies by software. Some "web forums" (shouldn't that be
fora?) do encourage "quoting" (by "encourage", I mean, the nature of the
software, not the ethos of the participants), but the Google interface
(have you actually seen it?) is particularly good at making you think that
it all just strings together (exists as a unit) and that "quoting" would be
not only superfluous, but silly. |
|
| Back to top |
|
 |
Shastri Guest
|
Posted: Sat Jan 28, 2006 5:00 pm Post subject: Re: Permutation problem |
|
|
Hello Rajesh,
Here is something to play with:
#include <stdio.h>
#define N 5
int main(char *argv[],int argc)
{
char list[5]={'a','b','c','d','e'};
permute(list,0,N);
return(0);
}
void permute(char list[],int k, int m)
{
int i;
char temp;
if(k==m)
{
/* PRINT A FROM k to m! */
for(i=0;i<N;i++){printf("%c",list[i]);}
printf("\n");
}
else
{
for(i=k;i<m;i++)
{
/* swap(a[i],a[m-1]); */
temp=list[i];
list[i]=list[m-1];
list[m-1]=temp;
permute(list,k,m-1);
/* swap(a[m-1],a[i]); */
temp=list[m-1];
list[m-1]=list[i];
list[i]=temp;
}
}
}
Cheers
Shastri
Rajesh wrote:
| Quote: | Hello Everybody,
Can anybody help me in writing a C program to generate and print all
possible combinations of n numbers.
For eg. for 3 numbers(1,2,3) there turn out 3! combinations.
(1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), (3,2,1). |
|
|
| Back to top |
|
 |
Peter Koller Guest
|
Posted: Sat Jan 28, 2006 7:00 pm Post subject: Re: Invoking other executable prgms using C? |
|
|
Pravin wrote:
| Quote: | hi
Is it possible to open an executable program like NOTEPAD(win)
using C-Program...(other than the function system() )? if so,please
provide me with an eg code...if not why?
Thanks in advance.
|
Dead easy:-
BOOL StartProgram(PCHAR program, PCHAR params)
{
STARTDATA SData = {0};
APIRET rc = 0;
PID pid = 0;
ULONG ulSessID = 0;
char achObjBuf[256] = {0};
SData.Length = sizeof(STARTDATA);
SData.Related = SSF_RELATED_INDEPENDENT;
SData.FgBg = SSF_FGBG_FORE;
SData.TraceOpt = SSF_TRACEOPT_NONE;
SData.PgmTitle = NULL;
SData.PgmName = program;
SData.PgmInputs = params;
SData.TermQ = NULL;
SData.InheritOpt = SSF_INHERTOPT_PARENT;
SData.SessionType = SSF_TYPE_DEFAULT;
SData.PgmControl = SSF_CONTROL_VISIBLE;
SData.ObjectBuffer = achObjBuf;
SData.ObjectBuffLen = 256;
rc = DosStartSession(&SData, &ulSessID, &pid);
if(rc != 0) return(FALSE);
return(TRUE);
}
...at least that is how it's done in OS/2
Yours,
Peter |
|
| Back to top |
|
 |
joev Guest
|
Posted: Sat Jan 28, 2006 8:00 pm Post subject: Re: user defined function that converts string to float |
|
|
| use sprintf see prinf format info |
|
| Back to top |
|
 |
Keith Thompson Guest
|
Posted: Sat Jan 28, 2006 8:00 pm Post subject: Re: Question about the clc string lib |
|
|
Sjouke Burry <burrynulnulfour (AT) ppllaanneett (DOT) nnlll> writes:
| Quote: | Jordan Abel wrote:
On 2006-01-28, CBFalconer <cbfalconer (AT) yahoo (DOT) com> wrote:
Strings of length approaching SIZE_MAX are so common in my code
that I worry about this possibility all the time. They are playing
havoc with my printer, and eating up the toner. It is especially
bad when I have to dump those strings out on a 110 baud ASR33
Teletype. Wears out the clutch and makes holes in the ribbon.
I challenge any c.l.c reader to provide any real working code that
uses a string of even SIZE_MAX / 2 length.
A medium-length text file embedded as a char[] object is about the
only
way i see this making sense - and that's for a SIZE_MAX of 65536.
Assuming an average line length of 64, that's 1024 lines, or 17 pages at
60 lines per page.
[I assume an ASR33 can handle printing 17 pages of text, or half that
anyway, even if it will take a few... hour and a half or so]
What makes you want a whole document inside a
single string??
If you approach programming that way,be prepared
for a lot of problems(especially those 4GB files).
|
Suppose you want to sort it. Having the whole thing in memory (if it
fits) is a *lot* more efficient than trying to sort it on disk.
--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. |
|
| Back to top |
|
 |
Thad Smith Guest
|
Posted: Sat Jan 28, 2006 8:00 pm Post subject: Re: Second Highest number in an array |
|
|
CBFalconer wrote:
| Quote: |
Joe Wright wrote:
Jaspreet wrote:
Just thinking what is a good way of getting second highest
value in an integer array.
....
However there has to be a better and more efficient way of
doing this. Please just let me know some hints and I would try
it on my own in C.
#include <stdio.h
int main(void) {
int pri, sec, i, v;
int arr[] = {4,10,3,8,6,7,2,7,9,2,0};
pri = sec = 0;
for (i = 0; arr[i]; ++i) {
v = arr[i];
if (v > pri) sec = pri, pri = v;
if (v > sec && v < pri) sec = v;
}
printf("pri is %d, sec is %d\n", pri, sec);
return 0;
}
|
If zero termination of the array is not specified, the loop control is
incorrect. The correct termination is
for (i=0; i < sizeof arr/sizeof *arr; i++)
I usually define a macro
#define DIM(a) (sizeof(a)/sizeof(a[0]))
for such use.
Note, in general, it is more robust to terminate a list on something
other than a special data value.
As someone else pointed out, this fails for all negative numbers,
since the initial value is larger than array values. In general, you
need a separate indication that no value has been found. You can a
maximum negative value as a place holder if you constrain the data to
not include the maximum negative value.
| Quote: | On the principle of "look to the innermost loop", why the extra
test?
for (i = 0, v = arr[0]; v; v = arr[++i])
if (v > pri) {sec = pri; pri = v;}
else if (v > sec) sec = v;
|
The replacement code is functionally different. It returns the value
of the element in the second position when ordered by descending value
and allowing duplicates, whereas the first version returns the second
highest value when each value is only represented once.
My interpretation of the literal definition of "second highest value"
would be the latter, based on "second highest" never being the same as
"highest". This is often not the colloquial meaning of second
highest, but I would prefer literal interpretation here, unless
specified otherwise.
--
Thad |
|
| Back to top |
|
 |
Keith Thompson Guest
|
Posted: Sat Jan 28, 2006 9:00 pm Post subject: Re: Question about the clc string lib |
|
|
Keith Thompson <kst-u (AT) mib (DOT) org> writes:
| Quote: | Sjouke Burry <burrynulnulfour (AT) ppllaanneett (DOT) nnlll> writes:
[...]
What makes you want a whole document inside a
single string??
If you approach programming that way,be prepared
for a lot of problems(especially those 4GB files).
Suppose you want to sort it. Having the whole thing in memory (if it
fits) is a *lot* more efficient than trying to sort it on disk.
|
Correction: it's *likely* to be a lot more efficient. (C doesn't say
anything about the relative efficiency of memory access vs. disk
access, and thrashing on a virtual memory system can slow things down
considerably.)
--
Keith Thompson (The_Other_Keith) kst-u (AT) mib (DOT) org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|