Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #74409 > unrolled thread
| Started by | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| First post | 2015-10-31 09:00 +0100 |
| Last post | 2015-11-01 16:36 -0800 |
| Articles | 19 on this page of 39 — 15 participants |
Back to article view | Back to comp.lang.c
The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-10-31 09:00 +0100
Re: The C Containers library Noob <root@127.0.0.1> - 2015-10-31 10:22 +0100
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-31 02:46 -0700
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-10-31 16:41 +0100
Re: The C Containers library Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-10-31 12:48 +0100
Re: The C Containers library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-31 12:21 +0000
Re: The C Containers library Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-10-31 14:31 +0100
Re: The C Containers library Noob <root@127.0.0.1> - 2015-10-31 13:35 +0100
Re: The C Containers library Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-10-31 14:33 +0100
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-10-31 16:45 +0100
Re: The C Containers library Keith Thompson <kst-u@mib.org> - 2015-10-31 13:46 -0700
Re: The C Containers library Robert Wessel <robertwessel2@yahoo.com> - 2015-11-01 01:31 -0500
Re: The C Containers library Ian Collins <ian-news@hotmail.com> - 2015-11-01 20:34 +1300
Re: The C Containers library Robert Wessel <robertwessel2@yahoo.com> - 2015-11-01 01:38 -0500
Re: The C Containers library Keith Thompson <kst-u@mib.org> - 2015-11-01 01:22 -0800
Re: The C Containers library Richard Heathfield <rjh@cpax.org.uk> - 2015-11-01 09:20 +0000
Re: The C Containers library supercat@casperkitty.com - 2015-11-01 07:51 -0800
Re: The C Containers library gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-01 15:57 +0000
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-01 17:41 +0100
Re: The C Containers library gazelle@shell.xmission.com (Kenny McCormack) - 2015-11-01 16:53 +0000
Re: The C Containers library Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-11-01 12:01 -0500
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-01 22:44 +0100
Re: The C Containers library Johannes Bauer <dfnsonfsduifb@gmx.de> - 2015-11-05 11:16 +0100
Re: The C Containers library Keith Thompson <kst-u@mib.org> - 2015-11-05 09:24 -0800
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-10-31 16:23 +0100
Re: The C Containers library Melzzzzz <mel@zzzzz.com> - 2015-10-31 16:33 +0100
Re: The C Containers library Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-31 11:51 -0700
Re: The C Containers library Melzzzzz <mel@zzzzz.com> - 2015-10-31 22:04 +0100
Re: The C Containers library Noob <root@127.0.0.1> - 2015-10-31 19:29 +0100
Re: The C Containers library Keith Thompson <kst-u@mib.org> - 2015-10-31 13:40 -0700
Re: The C Containers library "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-11-01 12:09 -0800
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-01 22:39 +0100
Re: The C Containers library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-01 22:50 +0000
Re: The C Containers library jacobnavia <jacob@jacob.remcomp.fr> - 2015-11-02 00:07 +0100
Re: The C Containers library Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-11-01 23:38 +0000
Re: The C Containers library fir <profesor.fir@gmail.com> - 2015-11-01 16:11 -0800
Re: The C Containers library fir <profesor.fir@gmail.com> - 2015-11-02 08:15 -0800
Re: The C Containers library fir <profesor.fir@gmail.com> - 2015-11-01 16:27 -0800
Re: The C Containers library fir <profesor.fir@gmail.com> - 2015-11-01 16:36 -0800
Page 2 of 2 — ← Prev page 1 [2]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2015-11-01 12:01 -0500 |
| Message-ID | <pzrZx.5169$cs.1446@fx31.iad> |
| In reply to | #74569 |
On Sunday November 1 2015 11:41, in comp.lang.c, "jacobnavia" <jacob@jacob.remcomp.fr> wrote: > Le 01/11/2015 16:51, supercat@casperkitty.com a écrit : >> On Sunday, November 1, 2015 at 3:20:33 AM UTC-6, Richard Heathfield wrote: >>> Well, it's not an "issue" in the sense of requiring a diagnostic >>> message. It remains an issue in the sense of being appallingly ugly >>> code. If we say we're going to return an int, the least we can do is >>> have the courtesy to return an int. >> >> IMHO, the proper "fix" would have been to legitimize "void main(...)" and >> say that a function declared in that fashion would return 0 (returning >> another status value would require an "exit" call). Not only would that >> make things cleaner in the case where any normal program termination will >> return 0, but it would also be useful for programs which will never reach >> the end of main. Having a function declared as returning "int" when there >> is no circumstance when it will actually do so seems a little dubious. >> > > No matter what the subject is, all discussions in this group end with > > int main(void) > or > void main(void) Hardly, Jacob. In fact, I've participated in this group for ~20 years, and I've noticed that very few discussions _end_ with a choice between two variants of a declaration of main(). > Not a word about the containers library "The" containers library? I was unaware that the standard C included /any/ containers library. I doubt that any one container library for C could be called "The" containers library. Don't you mean "a" containers library, or perhaps "my" (Jacob Navia's) containers library? -- Lew Pitcher "In Skills, We Trust" PGP public key available upon request
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2015-11-01 22:44 +0100 |
| Message-ID | <n160vv$s4c$1@dont-email.me> |
| In reply to | #74572 |
Le 01/11/2015 18:01, Lew Pitcher a écrit : > On Sunday November 1 2015 11:41, in comp.lang.c, "jacobnavia" > <jacob@jacob.remcomp.fr> wrote: > >> Le 01/11/2015 16:51, supercat@casperkitty.com a écrit : >>> On Sunday, November 1, 2015 at 3:20:33 AM UTC-6, Richard Heathfield wrote: >>>> Well, it's not an "issue" in the sense of requiring a diagnostic >>>> message. It remains an issue in the sense of being appallingly ugly >>>> code. If we say we're going to return an int, the least we can do is >>>> have the courtesy to return an int. >>> >>> IMHO, the proper "fix" would have been to legitimize "void main(...)" and >>> say that a function declared in that fashion would return 0 (returning >>> another status value would require an "exit" call). Not only would that >>> make things cleaner in the case where any normal program termination will >>> return 0, but it would also be useful for programs which will never reach >>> the end of main. Having a function declared as returning "int" when there >>> is no circumstance when it will actually do so seems a little dubious. >>> >> >> No matter what the subject is, all discussions in this group end with >> >> int main(void) >> or >> void main(void) > > Hardly, Jacob. > > In fact, I've participated in this group for ~20 years, and I've noticed that > very few discussions _end_ with a choice between two variants of a > declaration of main(). The discussion ends there. Of course there are the regs that will continue to speak their empty stuff for ages but nobody cares about them of course but me :-) > >> Not a word about the containers library > > "The" containers library? > I was unaware that the standard C included /any/ containers library. I doubt > that any one container library for C could be called "The" containers > library. > Note that it is YOU that puts that word in uppercase, since I used the lower case, meaning the containers library that is the subject of this thread and not the prototype of main dude!
[toc] | [prev] | [next] | [standalone]
| From | Johannes Bauer <dfnsonfsduifb@gmx.de> |
|---|---|
| Date | 2015-11-05 11:16 +0100 |
| Message-ID | <n1faa7$db4$1@news.albasani.net> |
| In reply to | #74493 |
On 31.10.2015 21:46, Keith Thompson wrote: >> Has probably UB (return missing). > > If you're referring to the lack of a return statement at the end of > main(), that's not an issue. In C++ (as in C starting with C90), > reaching the closing "}" of main() does an implicit `return 0;`. I was. Thanks for your pointer, learned something new. Interesting! Best regards, Johannes -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht öffentlich! Ah, der neueste und bis heute genialste Streich unsere großen Kosmologen: Die Geheim-Vorhersage. - Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$1@speranza.aioe.org>
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2015-11-05 09:24 -0800 |
| Message-ID | <lnfv0k5ph0.fsf@kst-u.example.com> |
| In reply to | #74943 |
Johannes Bauer <dfnsonfsduifb@gmx.de> writes:
> On 31.10.2015 21:46, Keith Thompson wrote:
>>> Has probably UB (return missing).
>>
>> If you're referring to the lack of a return statement at the end of
>> main(), that's not an issue. In C++ (as in C starting with C90),
>> reaching the closing "}" of main() does an implicit `return 0;`.
>
> I was. Thanks for your pointer, learned something new. Interesting!
And in case people have forgotten the correction I posted earlier, this
rule was introduced to C in C99, not C90.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2015-10-31 16:23 +0100 |
| Message-ID | <n12m8n$ere$1@dont-email.me> |
| In reply to | #74409 |
Le 31/10/2015 09:00, jacobnavia a écrit :
#include <containers.h>
int main(void)
{
strCollection *myData =
istrCollection.CreateFromFile("mydata.txt");
istrCollection.Sort(myData);
istrCollection.WriteToFile(myData,"mySortedData.txt");
return 0;
}
When you call a method you should use the interface. The "i" was missing.
Sorry about that.
[toc] | [prev] | [next] | [standalone]
| From | Melzzzzz <mel@zzzzz.com> |
|---|---|
| Date | 2015-10-31 16:33 +0100 |
| Message-ID | <20151031163338.78f085fa@maxa-pc> |
| In reply to | #74439 |
On Sat, 31 Oct 2015 16:23:07 +0100
jacobnavia <jacob@jacob.remcomp.fr> wrote:
> Le 31/10/2015 09:00, jacobnavia a écrit :
>
> #include <containers.h>
>
> int main(void)
> {
> strCollection *myData =
> istrCollection.CreateFromFile("mydata.txt");
> istrCollection.Sort(myData);
> istrCollection.WriteToFile(myData,"mySortedData.txt");
> return 0;
> }
>
>
>
> When you call a method you should use the interface. The "i" was
> missing.
>
> Sorry about that.
>
>
What about something concrete? Like parsing CSV file and sorting on eg
third field in a record, placing in eg binary tree?
[toc] | [prev] | [next] | [standalone]
| From | Malcolm McLean <malcolm.mclean5@btinternet.com> |
|---|---|
| Date | 2015-10-31 11:51 -0700 |
| Message-ID | <fc5089c0-2d99-46b7-a0b4-4fa18bfdabd4@googlegroups.com> |
| In reply to | #74440 |
On Saturday, October 31, 2015 at 3:33:47 PM UTC, Melzzzzz wrote: > > What about something concrete? Like parsing CSV file and sorting on eg > third field in a record, placing in eg binary tree? > I wrote a csv parser a while ago. But it trades quite a lot of efficiency for convenience. That wasn't likely to be a problem for what I wanted it for - the files represented scientific data which, while collected automatically, still took substantial time to generate (you get about 10,000 samples per experiment, but each experiment would to take at least a day to set up and run, so you're not going to stress a modern desktop system). The parser has no facilities for sorting on a field. So you'd extract the data to a structure and sort, then convert back to CSV if that was the output you wanted. So in running a C++ vs C test, what question are you trying to answer?
[toc] | [prev] | [next] | [standalone]
| From | Melzzzzz <mel@zzzzz.com> |
|---|---|
| Date | 2015-10-31 22:04 +0100 |
| Message-ID | <20151031220421.263e7c82@maxa-pc> |
| In reply to | #74470 |
On Sat, 31 Oct 2015 11:51:05 -0700 (PDT)
Malcolm McLean <malcolm.mclean5@btinternet.com> wrote:
> On Saturday, October 31, 2015 at 3:33:47 PM UTC, Melzzzzz wrote:
> >
> > What about something concrete? Like parsing CSV file and sorting on
> > eg third field in a record, placing in eg binary tree?
> >
> I wrote a csv parser a while ago.
>
> But it trades quite a lot of efficiency for convenience. That wasn't
> likely to be a problem for what I wanted it for - the files
> represented scientific data which, while collected automatically,
> still took substantial time to generate (you get about 10,000 samples
> per experiment, but each experiment would to take at least a day to
> set up and run, so you're not going to stress a modern desktop
> system).
>
> The parser has no facilities for sorting on a field. So you'd
> extract the data to a structure and sort, then convert back to
> CSV if that was the output you wanted.
>
> So in running a C++ vs C test, what question are you trying to
> answer?
>
I wanted to see how much effort requires container library for such
task. eg, in d it is this:
dict_t parseFeedFile(string fileName) {
dict_t rc;
auto f = new std.stream.File(fileName);
foreach(record;
csvReader!(string[string],Malformed.ignore)(f.toString(), null,'\t'))
{
rc[record["PRODUCT_ID"]]=record;
}
return rc;
}
More effort in C++ as there is no csv parser in standard library. But it
is interesting to see anyway.
[toc] | [prev] | [next] | [standalone]
| From | Noob <root@127.0.0.1> |
|---|---|
| Date | 2015-10-31 19:29 +0100 |
| Message-ID | <n1316j$rv0$1@dont-email.me> |
| In reply to | #74439 |
On 31/10/2015 16:23, jacobnavia wrote:
> #include <containers.h>
>
> int main(void)
> {
> strCollection *myData =
> istrCollection.CreateFromFile("mydata.txt");
> istrCollection.Sort(myData);
> istrCollection.WriteToFile(myData,"mySortedData.txt");
> return 0;
> }
>
> When you call a method you should use the interface. The "i" was missing.
So the istrCollection object emulates a namespace?
Style nit: your indentation choice is confusing IMO.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Date | 2015-10-31 13:40 -0700 |
| Message-ID | <lnbnbe93gk.fsf@kst-u.example.com> |
| In reply to | #74409 |
jacobnavia <jacob@jacob.remcomp.fr> writes:
[...]
> The C containers library is written in C and features nice stuff. Fully
> open source (no license) available at:
>
> https://code.google.com/p/ccl/
"Project Hosting on Google Code will close on January 25th, 2016."
You might consider migrating to another site. I use GitHub myself;
there's even an "Export to GitHub" button on the web page.
The web page says it's under the "New BSD License". Was that your
choice, or was it the default when you set up the project? I offer
no opinion on how or whether you *should* license your project,
but the phrase "no license" is unclear. You can release it to
the public domain if you like, but be aware that "public domain",
"open source", and "no license" are three *very* different things.
(I'm curious to see how and whether you manage to interpret this
as a personal attack.)
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <nospam@nospam.nospam> |
|---|---|
| Date | 2015-11-01 12:09 -0800 |
| Message-ID | <n15rhs$fj7$1@speranza.aioe.org> |
| In reply to | #74409 |
> "jacobnavia" wrote in message news:n11san$o70$1@dont-email.me... > Recently, discussing in the C++ group, somebody wrote: FWIW, your code is nice and easy to read! :^D
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2015-11-01 22:39 +0100 |
| Message-ID | <n160mp$qoo$1@dont-email.me> |
| In reply to | #74579 |
Le 01/11/2015 21:09, Chris M. Thomasson a écrit : >> "jacobnavia" wrote in message news:n11san$o70$1@dont-email.me... > >> Recently, discussing in the C++ group, somebody wrote: > > FWIW, your code is nice and easy to read! > > :^D Thanks. What do you think of the ideas? For instance, I have refrained from doing yet another computer language and used the C preprocessor. What limitations are there?
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-11-01 22:50 +0000 |
| Message-ID | <87r3k95o7n.fsf@bsb.me.uk> |
| In reply to | #74585 |
jacobnavia <jacob@jacob.remcomp.fr> writes:
<snip>
> What do you think of the ideas?
>
> For instance, I have refrained from doing yet another computer
> language and used the C preprocessor. What limitations are there?
Two thing strike me. First, I'm not sure who would use this sort of
library. For many quick scripting tasks I'd use awk, Perl or Python.
For a heavy-weight application I'd probably use C++. People targeting
small processors probably want something very lightweight. What kind of
programmer, doing what kind of work, wants this sort of library in C?
The second thing is more technical. I'm not sure how well do your
containers nest? For example, to list the positions in some data where
all the various words occur, I can use a map of vectors like this:
#include <vector>
#include <iostream>
#include <string>
#include <map>
int main()
{
typedef std::string::size_type size_type;
std::map<std::string, std::vector<size_type>> positions;
std::string word;
while (std::cin >> word)
positions[word].push_back((size_type)std::cin.tellg() - word.length());
for (auto it = positions.cbegin(); it != positions.cend(); it++) {
std::cout << it->first;
for (auto vi = it->second.cbegin(); vi != it->second.cend(); vi++)
std::cout << " " << *vi;
std::cout << "\n";
}
}
What does that look like using your CCL?
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2015-11-02 00:07 +0100 |
| Message-ID | <n165qn$goq$1@dont-email.me> |
| In reply to | #74593 |
Le 01/11/2015 23:50, Ben Bacarisse a écrit : > irst, I'm not sure who would use this sort of > library. For many quick scripting tasks I'd use awk, Perl or Python. > For a heavy-weight application I'd probably use C++. People targeting > small processors probably want something very lightweight. What kind of > programmer, doing what kind of work, wants this sort of library in C? Yes, you are right who would use C? For many quick scripting tasks you can use awk, Perl or Python. For a heavy-weight application you would probably use C++. People targeting small processors just do not use red/black trees or hash tables, or extensible vectors since they should always roll again their own and rewrite them at each application. What kind of programmer is left there? C programmers, of course. I have proved that all the complexity of C++ is unnecessary and that pleases no one here.
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-11-01 23:38 +0000 |
| Message-ID | <87lhah5lyt.fsf@bsb.me.uk> |
| In reply to | #74594 |
jacobnavia <jacob@jacob.remcomp.fr> writes: > Le 01/11/2015 23:50, Ben Bacarisse a écrit : >> irst, I'm not sure who would use this sort of >> library. For many quick scripting tasks I'd use awk, Perl or Python. >> For a heavy-weight application I'd probably use C++. People targeting >> small processors probably want something very lightweight. What kind of >> programmer, doing what kind of work, wants this sort of library in C? > > Yes, you are right who would use C? I didn't say that. Why ask for comment and the reply sarcastically? Do you want to address the other, technical, point? <snip> > [...] I have proved that all the complexity of C++ > is unnecessary and that pleases no one here. Well, I asked for an example and you did not provide one. You are under no obligation, of course, but it would help prove the point the complexity of C++ is unnecessary. -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | fir <profesor.fir@gmail.com> |
|---|---|
| Date | 2015-11-01 16:11 -0800 |
| Message-ID | <eff4e365-26b2-4bcb-a744-18951e115516@googlegroups.com> |
| In reply to | #74409 |
this way of doing operations on text is imo VERY good one (I was writing on this like 3 years ago in pl usenet not sure if here too,
i posted about making a container that could
be used to simply index things like parts pages accapites, sentences, words, letters
just by indexing like text = load("book.txt")
then use some indexing on the text container to get say 7 word in 67 sentence, tehen call some functions (like reverse, translate and so on) on it
this is very good way of working on texts imo and i was focusing on it though a bit later i lost my focus without answering to myself some urgent questions (like for example: how would look it in normal c (*), do it need c improvements to make it much better)
(*) more precise i even started to code this (as i now remember), the container data was hidden, there was indexing data filled at time of load the text to this hidden container memory, and simple c api to use it normal way to every operation imaginable
(hidden container was only one, or identified by handle which was number or
pointer to string, sorta like that)
I called this module text worker so if
you asking on it (im tired and not sure what you asking about) the interface was like
text_worker_load_file("book.txt");
chunk tenth_word = text_worker_find_word(10); //chunk would be like pointer + size
text_worker_replace_string(tenth_word, "zz");
such implementation and interface is most probably bad and not optimal but the general idea is still very good and i was happy to find this idea myself (but now im bored and i doubt if i will find much time to work on it, things like agent programming may be more urgent (yet im bored with that too))
[toc] | [prev] | [next] | [standalone]
| From | fir <profesor.fir@gmail.com> |
|---|---|
| Date | 2015-11-02 08:15 -0800 |
| Message-ID | <e4a0e2a7-63cf-490f-93d5-6a3f4ce00138@googlegroups.com> |
| In reply to | #74605 |
one good question is for example if some would have ideal interface (when text is the whole text container/ worker) how it would look like say one want this said sort by the words lines tellers etc, or one need just to reach,/reference given letter, line, word, paragraph 1) text.word[i] is imo quite ugly 2) test.sort_lines() looks better though seems for me too not to much optimal AD1) oldschool looking ((word) text)[i] for referencing words maybe look a bit better, it seems like it violates some c rules (like such way of whole array or container re-casting) but this violations may seem at least like partially torrelable but, really?, (rationale - why) and what else (fir)
[toc] | [prev] | [next] | [standalone]
| From | fir <profesor.fir@gmail.com> |
|---|---|
| Date | 2015-11-01 16:27 -0800 |
| Message-ID | <4a00b118-a766-448f-bed8-556ae695b140@googlegroups.com> |
| In reply to | #74409 |
W dniu sobota, 31 października 2015 09:00:42 UTC+1 użytkownik jacobnavia napisał:
> Recently, discussing in the C++ group, somebody wrote:
>
> Now the challenge is:
>
> "You have a file with an unknown number of text lines of variable
> lengths. Read the lines and write them out sorted in another file.
>
> Please do this in less than 10x the number of lines of C code, and make
> it run faster."
>
>
> The C++ solution:------------------------------------------
> #include <vector>
> #include <fstream>
> #include <algorithm>
> #include <string>
>
> using namespace std;
>
> int main(int argc,char* argv[])
> {
> char* file = argv[2]; // input file name
> char* ofile = argv[3]; // output file name
>
> vector<string> buf;
>
> fstream fin(file, ios::in);
> string d;
> while(getline(fin, d)) buf.push_back(d); //add line to buf
>
> sort(buf.begin(), buf.end());
>
> fstream fout(ofile, ios::out);
> copy(buf.begin(), buf.end(), ostream_iterator<string>(fout,"\n"));
>
> }
>
> The C solution---------------------------------------------
>
> #include <containers.h>
>
> int main(void)
> {
> strCollection *myData =
> strCollection.CreateFromFile("mydata.txt");
> strCollection.Sort(myData);
> strCollection.WriteToFile(myData,"mySortedData.txt");
> return 0;
> }
>
>
> We can see that the solution in C is just as short as the C++ solution.
> The C containers library allows C programmers to have the same level of
> abstraction than C++ in a key feature: containers.
>
> The C containers library is written in C and features nice stuff. Fully
> open source (no license) available at:
>
> https://code.google.com/p/ccl/
from the point of view following what i was sayin a moment before in c you may do
void main()
{
tw_load("book.txt"):
tw_sort_words();
tw_store("book_out.txt");
}
your sort was misleading becouse you may sort letters words accapites
the tw_ prefix is ugly but in the moment im not sure if in c you can replace it just by
tw.load("book.txt") (you mean load is a pointer to function in tw structure? it probably wouldnt work or work well in present c)
[toc] | [prev] | [next] | [standalone]
| From | fir <profesor.fir@gmail.com> |
|---|---|
| Date | 2015-11-01 16:36 -0800 |
| Message-ID | <f2d3ae92-dabe-41ce-91dd-94ed00e18ab4@googlegroups.com> |
| In reply to | #74608 |
W dniu poniedziałek, 2 listopada 2015 01:28:00 UTC+1 użytkownik fir napisał:
> W dniu sobota, 31 października 2015 09:00:42 UTC+1 użytkownik jacobnavia napisał:
> > Recently, discussing in the C++ group, somebody wrote:
> >
> > Now the challenge is:
> >
> > "You have a file with an unknown number of text lines of variable
> > lengths. Read the lines and write them out sorted in another file.
> >
> > Please do this in less than 10x the number of lines of C code, and make
> > it run faster."
> >
> >
> > The C++ solution:------------------------------------------
> > #include <vector>
> > #include <fstream>
> > #include <algorithm>
> > #include <string>
> >
> > using namespace std;
> >
> > int main(int argc,char* argv[])
> > {
> > char* file = argv[2]; // input file name
> > char* ofile = argv[3]; // output file name
> >
> > vector<string> buf;
> >
> > fstream fin(file, ios::in);
> > string d;
> > while(getline(fin, d)) buf.push_back(d); //add line to buf
> >
> > sort(buf.begin(), buf.end());
> >
> > fstream fout(ofile, ios::out);
> > copy(buf.begin(), buf.end(), ostream_iterator<string>(fout,"\n"));
> >
> > }
> >
> > The C solution---------------------------------------------
> >
> > #include <containers.h>
> >
> > int main(void)
> > {
> > strCollection *myData =
> > strCollection.CreateFromFile("mydata.txt");
> > strCollection.Sort(myData);
> > strCollection.WriteToFile(myData,"mySortedData.txt");
> > return 0;
> > }
> >
> >
> > We can see that the solution in C is just as short as the C++ solution.
> > The C containers library allows C programmers to have the same level of
> > abstraction than C++ in a key feature: containers.
> >
> > The C containers library is written in C and features nice stuff. Fully
> > open source (no license) available at:
> >
> > https://code.google.com/p/ccl/
>
> from the point of view following what i was sayin a moment before in c you may do
>
> void main()
> {
> tw_load("book.txt"):
> tw_sort_words();
> tw_store("book_out.txt");
> }
>
> your sort was misleading becouse you may sort letters words accapites
>
> the tw_ prefix is ugly but in the moment im not sure if in c you can replace it just by
> tw.load("book.txt") (you mean load is a pointer to function in tw structure? it probably wouldnt work or work well in present c)
ps if you use function pointers here
strCollection.WriteToFile(myData,"mySortedData.txt");
how WriteToFile pointes function knows how to obtain the tied strCollection structure pointer? If WriteToFile just calls this function this funstion is AFAIK agnostic to
the structure that contains pointer that fired that.. (?)
[sorry im to tired (outfocused) to tread source or think much but i wonder)
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.c
csiph-web