Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Create a Copy of Files

6 views
Skip to first unread message

Hans

unread,
May 8, 2009, 9:09:02 PM5/8/09
to
I'm creating a utility program to create empty text files using the
filenames PDFs, but with the case--upper and lower--preserved. I need
a duplicate file with zero footprint on the HD for indexing purposes.
Can anybody help me with this? I managed to write something in another
language, but it came out all in lowercase so I'm looking into C.

Example
----------------------------
Input: 0763704814 - C++ Plus Data Structures, 3ed (Jones and
Bartlett-2003).pdf
Output: 0763704814 - C++ Plus Data Structures, 3ed (Jones and
Bartlett-2003).pdf.txt
---------------------------

And I also want to move the ISBN to the end.
----------------------------
Input: 0763704814 - C++ Plus Data Structures, 3ed (Jones and
Bartlett-2003).pdf
Output: C++ Plus Data Structures, 3ed (Jones and Bartlett-2003) -
0763704814.pdf.txt
---------------------------

BTW, I'm using Bloodshed Dev-C++ compiler.

CBFalconer

unread,
May 8, 2009, 9:55:30 PM5/8/09
to
Hans wrote:
>
> I'm creating a utility program to create empty text files using the
> filenames PDFs, but with the case--upper and lower--preserved. I need
> a duplicate file with zero footprint on the HD for indexing purposes.
> Can anybody help me with this? I managed to write something in another
> language, but it came out all in lowercase so I'm looking into C.

A .pdf file is NOT a text file. It is a binary file. Text files
are easily created with any text file editor.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.


Doug Miller

unread,
May 8, 2009, 10:25:12 PM5/8/09
to
In article <4A04E292...@yahoo.com>, cbfal...@maineline.net wrote:
>Hans wrote:
>>
>> I'm creating a utility program to create empty text files using the
>> filenames PDFs, but with the case--upper and lower--preserved. I need
>> a duplicate file with zero footprint on the HD for indexing purposes.
>> Can anybody help me with this? I managed to write something in another
>> language, but it came out all in lowercase so I'm looking into C.
>
>A .pdf file is NOT a text file. It is a binary file. Text files
>are easily created with any text file editor.
>
Missed the word 'empty' in the first line of the post, didja? :-)

Hans

unread,
May 8, 2009, 10:30:27 PM5/8/09
to

Yes, I know that.

The scenario is this. I download a lot of ebooks--PDF's, CHM's,
DJVU's, etc. I want to create a separate index using the operating
system's folders as a kind of catalog and store the ebooks elsewhere.
My solution is to create proxy files for the ebooks (i.e., empty text
files with the same names as the original). The text files now become
like catalog cards in the library. One "catalog card" (text file) will
have the ISBN in front and another has the book name in front.

I need to do the creation of the files in bulk because I download like
hundreds of ebooks per day. So, the cataloging part is really slowing
me down.

Keith Thompson

unread,
May 8, 2009, 10:33:48 PM5/8/09
to
CBFalconer <cbfal...@yahoo.com> writes:
> Hans wrote:
>> I'm creating a utility program to create empty text files using the
>> filenames PDFs, but with the case--upper and lower--preserved. I need
>> a duplicate file with zero footprint on the HD for indexing purposes.
>> Can anybody help me with this? I managed to write something in another
>> language, but it came out all in lowercase so I'm looking into C.
>
> A .pdf file is NOT a text file. It is a binary file. Text files
> are easily created with any text file editor.

He knows that. If you had read the rest of the article, or even the
part you quoted, you would understand that. He wants to create an
empty text file whose name is based on the name of an existing PDF
file.

If you're going to snip quoted text, can you please do us all the
simple courtesy of marking it somehow? "[snip]" and "[...]" are
commonly used markers.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Spiros Bousbouras

unread,
May 9, 2009, 12:12:05 AM5/9/09
to

Here's an approximation to what you want. You would
have to add more error checks based on the exact
format of your input.

#include <ctype.h>
#include <string.h>
#include <stdio.h>

void transform(const char *s , char *d) {
size_t i , isbn_end , suffix_beg ;

#define check_for_faulty_input { \
if ( s[i] == 0 ) { \
*d = 0 ; \
return ; \
} \
}

if ( !isdigit(s[0]) ) {
*d = 0 ;
return ;
}
while ( isdigit(s[i]) ) {
check_for_faulty_input
i++ ;
}
isbn_end = i-1 ;
while ( s[i++] ) ;
while ( s[i] != '.' ) {
if ( i == 0 ) {
*d = 0 ;
return ;
}
i-- ;
}
suffix_beg = i ;
strncpy(d , s+isbn_end+2 , suffix_beg-isbn_end-2) ;
d[suffix_beg-isbn_end-2] = ' ' ;
strncpy(d+(suffix_beg-isbn_end-1) , s , isbn_end+1 ) ;
strcpy(d+suffix_beg , s+suffix_beg) ;
}

int main(void) {
char d[1000] ,
*input = "0763704814 - C++"
" Plus Data Structures,"
" 3ed (Jones and Bartlett-2003).pdf" ;
transform(input,d) ;
printf("%s\n%s\n\n\n",input,d) ;
return 0 ;
}

--
When I'm feeling blue
baby I love you
camisole see-thru
dubi dubi du

Beej Jorgensen

unread,
May 9, 2009, 2:45:52 AM5/9/09
to
Hans <hanni...@gmail.com> wrote:
>Input: 0763704814 - C++ Plus Data Structures, 3ed (Jones and
>Bartlett-2003).pdf
>Output: C++ Plus Data Structures, 3ed (Jones and Bartlett-2003) -
>0763704814.pdf.txt

Probably a job for sscanf(), but there are a variety of options. Let's
assume filenames are in the form "ISBN - Title.ext":

#include <stdio.h>
#include <string.h>

int main(void)
{
char filename[] = "0763704814 - C++ Plus Data Structures, 3ed (Jones and Bartlett-2003).pdf";
char ext[16], isbn[16], title[512];
int num;

num = sscanf(filename, "%15s - %511[^.].%15s", isbn, title, ext);
if (num == 3) {
printf("%s - %s.%s.txt\n", title, isbn, ext);
} else {
printf("Parse failure\n");
}

return 0;
}

To create an empty file, you can just open it and close it, I'm pretty
sure:

FILE *fp;
char newfilename[768];

...

snprintf(newfilename, sizeof newfilename,
"%s - %s.%s.txt\n", title, isbn, ext);

fp = fopen(newfilename, "w"); // don't forget to error-check this
fclose(fp);

There I've used snprintf() to store the new file name in another string
so we could pass it to fopen(). (Use sprintf() if you don't have
snprintf().)

You might also consider a language like Python with better support for
regexs and walking directory trees.

-Beej

Hans

unread,
May 9, 2009, 4:00:47 AM5/9/09
to
> void transform(const char *s , char *d) {
>     size_t i , isbn_end , suffix_beg ;
>

I'm guessing this is the routine to move the ISBN to the end of the
filename. Anyway, I'll check it out and add it to what I've been
working on since this morning.

Thanks a million.

Hans

unread,
May 9, 2009, 4:03:54 AM5/9/09
to
>     int main(void)
>     {
>         char filename[] = "0763704814 - C++ Plus Data Structures, 3ed (Jones and Bartlett-2003).pdf";
>         char ext[16], isbn[16], title[512];
>         int num;
>
>         num = sscanf(filename, "%15s - %511[^.].%15s", isbn, title, ext);
>         if (num == 3) {
>             printf("%s - %s.%s.txt\n", title, isbn, ext);
>         } else {
>             printf("Parse failure\n");
>         }
>
>         return 0;
>     }
>

Hmm. This is an elegant solution. I'll try this out as well and get
back to you guys.

Thanks another million.

Spiros Bousbouras

unread,
May 9, 2009, 4:10:39 AM5/9/09
to

Yes, the aim is to produce the filename you wanted. But
your examples are not enough to show what are the
possible formats for the input or exactly what the output
should look like. So it's just a guess. It assumes that d
is an array of char at least as long as *s including the
terminating NUL.

--
Who's your mama?

Hans

unread,
May 9, 2009, 4:29:09 AM5/9/09
to
This is what I have so far. I got the code snippets from another forum
and combined it with Beej Jorgensen's code to move the ISBN to the
last part of the name. Now, I need a way to skip over files other than
PDF, CHM, DJVU, ZIP and RAR.

P.S. Please ignore the way I format the code. I'm not used to very
short variable names.

//----------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>

FILE *thisFile;

//---------------------------------------------------------
int main( int argc , char *argv[] ) {
//-------------------------------------------------------
struct dirent *themFiles;
char FileName[512];
char FileType[16];
char Title[512];
char ISBN[16];

int Matched;

DIR *thisFolder;
thisFolder = opendir( "." );

if ( thisFolder ) {

while ( ( themFiles = readdir( thisFolder ) ) != NULL ) {

printf( "%s\n", themFiles->d_name );

//------------------------------------------------------------------------
Matched = sscanf( themFiles->d_name , "%15s - %511[^.].%15s" ,
ISBN , Title , FileType );

if ( Matched == 3 ) {
printf( "%s - %s.%s.txt\n" , Title , ISBN , FileType );


} else {
printf( "Parse failure\n" );
}

//----------------------------------------------------
/* create the file

strcpy( FileName , themFiles->d_name );
strcat( FileName , ".txt" );
if ( ( thisFile = fopen( FileName , "w+" ) ) == NULL )
;
else
printf( "%s\n", FileName );

fclose( thisFile );
//*/

}

closedir( thisFolder );
}

system( "PAUSE" );
return 0;
}

Hans

unread,
May 9, 2009, 4:37:09 AM5/9/09
to

I checked out Beej Jorgensen's solution below and it worked well
moving the ISBN to the end part of the name. Anyway, as for the
possible inputs, I'm only concerned with those files with the 10-digit
ISBN at the beginning and I'll be skipping those without.

Spiros Bousbouras

unread,
May 9, 2009, 4:40:08 AM5/9/09
to
On 9 May, 09:29, Hans <hannibal...@gmail.com> wrote:
>
> //----------------------------------
> #include <stdio.h>
> #include <stdlib.h>
> #include <dirent.h>

If you use stuff outside of standard C you need to explain
what they do.

> #include <string.h>
>
> FILE *thisFile;
>
> //---------------------------------------------------------
> int main( int argc , char *argv[] ) {
> //-------------------------------------------------------
> struct dirent *themFiles;

Same here. What are the fields of the dirent structure?

> char FileName[512];
> char FileType[16];
> char Title[512];
> char ISBN[16];
>
> int Matched;
>
> DIR *thisFolder;
> thisFolder = opendir( "." );
>
> if ( thisFolder ) {
>
> while ( ( themFiles = readdir( thisFolder ) ) != NULL ) {
>
> printf( "%s\n", themFiles->d_name );
>
> //------------------------------------------------------------------------
> Matched = sscanf( themFiles->d_name , "%15s - %511[^.].%15s" ,
> ISBN , Title , FileType );
>
> if ( Matched == 3 ) {
> printf( "%s - %s.%s.txt\n" , Title , ISBN , FileType );
> } else {
> printf( "Parse failure\n" );

If the parse has failed I don't think it makes sense to go
on and create the new file so you probably need a continue
here.

> }
> //----------------------------------------------------
> /* create the file

> Rest of code snipped.

Hans

unread,
May 9, 2009, 4:54:32 AM5/9/09
to
I'm still working on the code placement. This was just to show that
the ISBN switch worked.

As for the dirent.h, it was from this webpage at the cprogramming.com
forum:

http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046380353&id=1044780608

I also checked the dirent.h file. It happened to be included in the
Bloodshed Dev-C/C++ compiler so it must be common or standard.

Hans

unread,
May 9, 2009, 9:14:25 AM5/9/09
to
I did it. It's finished. Thanks a million guys.

/*---------------------------------------------------------
Program : eBook Catalog Maker
Author : Hans alias Kanshu / Hanabi
Description : Creates proxy / empty files for ebooks of type
PDF, CHM, DJVU, RAR, ZIP
Date : 05/09/2009 2102H
Notes : Solutions provided by programmers from comp.lang.c
and cprogramming.com
*/

#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>

#include <string.h>

FILE *thisCard; // catalog card; proxy file

//---------------------------------------------------------
int main( int argc , char *argv[] ) {
//-------------------------------------------------------

struct dirent *thisFile;

char CatalogCard[768];


char FileType[16];
char Title[512];
char ISBN[16];

char TypePDF[] = "pdf";
char TypeCHM[] = "chm";
char TypeDJVU[] = "djvu";
char TypeZIP[] = "zip";
char TypeRAR[] = "rar";

int Matched;
int i;

DIR *thisFolder;
thisFolder = opendir( "." );

if ( thisFolder ) {

while ( ( thisFile = readdir( thisFolder ) ) != NULL ) {

// typical filename + extension
Matched = sscanf( thisFile->d_name , "%511[^.].%15s" , Title ,
FileType );

if ( Matched == 2 ) {

// recognize only PDF, CHM, DJVU, ZIP, RAR
for( i = 0 ; ( FileType[i] = tolower( FileType[i] ) ) ; i++ );

if ( ( strstr( FileType , TypePDF ) != NULL ) ||
( strstr( FileType , TypeCHM ) != NULL ) ||
( strstr( FileType , TypeDJVU ) != NULL ) ||
( strstr( FileType , TypeZIP ) != NULL ) ||
( strstr( FileType , TypeRAR ) != NULL ) ) {

// create 1st catalog card; ISBN card
//-----------------------------------------------------------------
if ( strstr( FileType , TypePDF ) != NULL )
snprintf( CatalogCard , sizeof CatalogCard ,
"%s.%s.txt" , Title , FileType );

// NOTE: MQH filetype is the MetaQuotes Language file
// that has a yellow icon in the file explorer
if ( ( strstr( FileType , TypeCHM ) != NULL ) ||
( strstr( FileType , TypeDJVU ) != NULL ) )
snprintf( CatalogCard , sizeof CatalogCard ,
"%s.%s.mqh" , Title , FileType );

if ( ( strstr( FileType , TypeRAR ) != NULL ) ||
( strstr( FileType , TypeZIP ) != NULL ) )
snprintf( CatalogCard , sizeof CatalogCard ,
"%s.%s.zip" , Title , FileType );

if ( ( thisCard = fopen( CatalogCard , "w+" ) ) == NULL )
printf( "Can't create file.\n" );
else
fclose( thisCard );

// create 2nd catalog card; Title + ISBN card
//-----------------------------------------------------------------
Matched = sscanf( thisFile->d_name , "%15s - %511[^.].


%15s" ,
ISBN , Title ,
FileType );

if ( Matched == 3 ) {

for( i = 0 ; ( FileType[i] = tolower( FileType[i] ) ) ; i+
+ );

if ( strstr( FileType , TypePDF ) != NULL )
snprintf( CatalogCard , sizeof CatalogCard ,
"%s - %s.%s.txt" , Title , ISBN , FileType );

if ( ( strstr( FileType , TypeCHM ) != NULL ) ||
( strstr( FileType , TypeDJVU ) != NULL ) )
snprintf( CatalogCard , sizeof CatalogCard ,
"%s - %s.%s.mqh" , Title , ISBN , FileType );

if ( ( strstr( FileType , TypeRAR ) != NULL ) ||
( strstr( FileType , TypeZIP ) != NULL ) )
snprintf( CatalogCard , sizeof CatalogCard ,
"%s - %s.%s.zip" , Title , ISBN , FileType );

if ( ( thisCard = fopen( CatalogCard , "w+" ) ) == NULL )
printf( "Can't create file.\n" );
else
fclose( thisCard );

Ben Bacarisse

unread,
May 9, 2009, 9:47:25 AM5/9/09
to
Hans <hanni...@gmail.com> writes:

> This is what I have so far.

Obviously since this is a C group and you asked about C you have had C
answers, but someone should say that it need not be this hard. If
you are using Linux (or other Unix-like system) it can be done in one
command. If not, there must be similar tools that do this sort of
maintenance job. System administrators have to do this sort of things
all the time.

If you are doing this to learn C then fine, but if not it will pay to
learn how to do this sort of thing on your system.

--
Ben.

Hans

unread,
May 9, 2009, 9:50:31 AM5/9/09
to

Some refinement needed. It's not skipping some text files.

Keith Thompson

unread,
May 9, 2009, 5:20:34 PM5/9/09
to
Hans <hanni...@gmail.com> writes:
> On May 9, 9:14�pm, Hans <hannibal...@gmail.com> wrote:
>> I did it. It's finished. Thanks a million guys.

Great. I see from your more recent followup that it's still got some
problems. It really wasn't necessary to quote the entire article to
add a one-line response -- but since I'll be commenting on your code
myself, I'll take advantage of it.

>> /*---------------------------------------------------------
>> Program � � : eBook Catalog Maker
>> Author � � �: Hans alias Kanshu / Hanabi
>> Description : Creates proxy / empty files for ebooks of type
>> � � � � � � � � PDF, CHM, DJVU, RAR, ZIP
>> Date � � � �: 05/09/2009 2102H
>> Notes � � � : Solutions provided by programmers from comp.lang.c
>> � � � � � � � � and cprogramming.com
>> */
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <dirent.h>

You should be aware that <dirent.h> is non-standard. More precisely,
it's not defined by the C standard. I believe it is defined by POSIX.
This shouldn't be a problem for your purposes, but it means that (a)
your program isn't entirely portable (which is probably unavoidable
unless you use some other means to get the list of files into your
program), and (b) questions about those aspects of your program should
be directed elsewhere, probably comp.unix.programmer or some forum
that deals with your implementation.

Standard C has no support for directories.

>> #include <string.h>
>>
>> FILE *thisCard; �// catalog card; proxy file
>>
>> //---------------------------------------------------------
>> � int main( int argc , char *argv[] ) {
>> //-------------------------------------------------------
>> � struct dirent *thisFile;
>>
>> � char CatalogCard[768];
>> � char FileType[16];
>> � char Title[512];
>> � char ISBN[16];
>>
>> � char TypePDF[] �= "pdf";
>> � char TypeCHM[] �= "chm";
>> � char TypeDJVU[] = "djvu";
>> � char TypeZIP[] �= "zip";
>> � char TypeRAR[] �= "rar";

I'd declare all these as const, since you're not going to be changing
them.

>> � int Matched;


>> � int i;
>>
>> � DIR *thisFolder;
>> � thisFolder = opendir( "." );
>>
>> � if ( thisFolder ) {

Presumably this tests whether the opendir() call succeeded -- but you
don't do anything if it fails. An error message would be good.

>> � � while ( ( thisFile = readdir( thisFolder ) ) != NULL ) {


>>
>> � � � // typical filename + extension
>> � � � Matched = sscanf( thisFile->d_name , "%511[^.].%15s" , Title ,
>> FileType );

511 and 15 are "magic numbers". At the very least, they should be
documented. Better yet, declare them as named constants.

>>
>> � � � if ( Matched == 2 ) {


>>
>> � � � � // recognize only PDF, CHM, DJVU, ZIP, RAR
>> � � � � for( i = 0 ; ( FileType[i] = tolower( FileType[i] ) ) ; i++ );
>>
>> � � � � if ( ( strstr( FileType , TypePDF ) �!= NULL ) ||
>> � � � � � � �( strstr( FileType , TypeCHM ) �!= NULL ) ||
>> � � � � � � �( strstr( FileType , TypeDJVU ) != NULL ) ||
>> � � � � � � �( strstr( FileType , TypeZIP ) �!= NULL ) ||
>> � � � � � � �( strstr( FileType , TypeRAR ) �!= NULL ) ) {

This screams out for an array and a loop.

>> � � � � � // create 1st catalog card; ISBN card


>> � � � � � //-----------------------------------------------------------------
>> � � � � � if ( strstr( FileType , TypePDF ) != NULL )
>> � � � � � � snprintf( CatalogCard , sizeof CatalogCard ,
>> � � � � � � � � � � � "%s.%s.txt" , Title , FileType );
>>
>> � � � � � // NOTE: MQH filetype is the MetaQuotes Language file
>> � � � � � // � that has a yellow icon in the file explorer
>> � � � � � if ( ( strstr( FileType , TypeCHM ) �!= NULL ) ||
>> � � � � � � � �( strstr( FileType , TypeDJVU ) != NULL ) )
>> � � � � � � snprintf( CatalogCard , sizeof CatalogCard ,
>> � � � � � � � � � � � "%s.%s.mqh" , Title , FileType );
>>
>> � � � � � if ( ( strstr( FileType , TypeRAR ) != NULL ) ||
>> � � � � � � � �( strstr( FileType , TypeZIP ) != NULL ) )
>> � � � � � � snprintf( CatalogCard , sizeof CatalogCard ,
>> � � � � � � � � � � � "%s.%s.zip" , Title , FileType );

Here you're taking slightly different actions depending on the file
extension, but it could still be table-driven. That would make
maintenance easier; if you need to add support for another file
extension later, just update the table.

>> � � � � � if ( ( thisCard = fopen( CatalogCard , "w+" ) ) == NULL )


>> � � � � � � printf( "Can't create file.\n" );

Error messages should be written to stdout.

>> � � � � � else


>> � � � � � � fclose( thisCard );
>>
>> � � � � � // create 2nd catalog card; Title + ISBN card
>> � � � � � //-----------------------------------------------------------------
>> � � � � � Matched = sscanf( thisFile->d_name , "%15s - %511[^.].
>> %15s" ,
>> � � � � � � � � � � � � � � � � � � � � � � � �ISBN , Title ,
>> FileType );
>>
>> � � � � � if ( Matched == 3 ) {
>>
>> � � � � � � for( i = 0 ; ( FileType[i] = tolower( FileType[i] ) ) ; i+
>> + );
>>
>> � � � � � � if ( strstr( FileType , TypePDF ) != NULL )
>> � � � � � � � snprintf( CatalogCard , sizeof CatalogCard ,
>> � � � � � � � � � � � � "%s - %s.%s.txt" , Title , ISBN , FileType );

snprintf() is a good way to avoid writing past the end of a buffer,
but if the buffer isn't big enough you just ignore the error. I'm not
sure how you should handle it, but ignoring the issue is rarely the
best solution. (Sometimes it is, but then you should document the
reasons.)

>> � � � � � � if ( ( strstr( FileType , TypeCHM ) �!= NULL ) ||


>> � � � � � � � � �( strstr( FileType , TypeDJVU ) != NULL ) )
>> � � � � � � � snprintf( CatalogCard , sizeof CatalogCard ,
>> � � � � � � � � � � � � "%s - %s.%s.mqh" , Title , ISBN , FileType );
>>
>> � � � � � � if ( ( strstr( FileType , TypeRAR ) != NULL ) ||
>> � � � � � � � � �( strstr( FileType , TypeZIP ) != NULL ) )
>> � � � � � � � snprintf( CatalogCard , sizeof CatalogCard ,
>> � � � � � � � � � � � � "%s - %s.%s.zip" , Title , ISBN , FileType );
>>
>> � � � � � � if ( ( thisCard = fopen( CatalogCard , "w+" ) ) == NULL )
>> � � � � � � � printf( "Can't create file.\n" );
>> � � � � � � else
>> � � � � � � � fclose( thisCard );
>>
>> � � � � � }
>> � � � � }
>> � � � }
>> � � }
>>
>> � � closedir( thisFolder );
>> � }
>>
>> � system( "PAUSE" );

This is unnecessarily system-specific.

>> � return 0;


>>
>> }
>>
>>
>
> Some refinement needed. It's not skipping some text files.

Personally, I would have implemented this in Perl.

Spiros Bousbouras

unread,
May 9, 2009, 5:30:53 PM5/9/09
to
On 9 May, 22:20, Keith Thompson <ks...@mib.org> wrote:

> Hans <hannibal...@gmail.com> writes:
> >> if ( ( thisCard = fopen( CatalogCard , "w+" ) ) == NULL )
> >> printf( "Can't create file.\n" );
>
> Error messages should be written to stdout.

You mean stderr.

--
Alalalala int alalalala int
alalalala int-int int-int int int

Keith Thompson

unread,
May 9, 2009, 5:56:21 PM5/9/09
to
Spiros Bousbouras <spi...@gmail.com> writes:
> On 9 May, 22:20, Keith Thompson <ks...@mib.org> wrote:
>> Hans <hannibal...@gmail.com> writes:
>> >> if ( ( thisCard = fopen( CatalogCard , "w+" ) ) == NULL )
>> >> printf( "Can't create file.\n" );
>>
>> Error messages should be written to stdout.
>
> You mean stderr.

Yeah. I seem to be making more than my share of dumb mistakes today.
Thanks for catching this one.

Spiros Bousbouras

unread,
May 9, 2009, 6:31:44 PM5/9/09
to
On 9 May, 22:56, Keith Thompson <ks...@mib.org> wrote:
>
> Yeah. I seem to be making more than my share of dumb mistakes today.
> Thanks for catching this one.

The "Float comparison" thread is taking its toll on you :-D

CBFalconer

unread,
May 9, 2009, 9:09:58 PM5/9/09
to
Hans wrote:
> CBFalconer <cbfalco...@yahoo.com> wrote:
>> Hans wrote:
>>
>>> I'm creating a utility program to create empty text files using
>>> the filenames PDFs, but with the case--upper and lower--preserved.
>>> I need a duplicate file with zero footprint on the HD for
>>> indexing purposes. Can anybody help me with this? I managed to
>>> write something in another language, but it came out all in
>>> lowercase so I'm looking into C.
>>
>> A .pdf file is NOT a text file. It is a binary file. Text files
>> are easily created with any text file editor.
>
> Yes, I know that.
>
> The scenario is this. I download a lot of ebooks--PDF's, CHM's,
> DJVU's, etc. I want to create a separate index using the operating
> system's folders as a kind of catalog and store the ebooks
> elsewhere. My solution is to create proxy files for the ebooks
> (i.e., empty text files with the same names as the original). The
> text files now become like catalog cards in the library. One
> "catalog card" (text file) will have the ISBN in front and another
> has the book name in front.
>
> I need to do the creation of the files in bulk because I download
> like hundreds of ebooks per day. So, the cataloging part is really
> slowing me down.

I think you are over complicating the project. You have a herd of
filenames, which names are not complete without the path to their
directories. Yet you want to be able to easily update that path.
Also some other information is probably required.

I would design a structure that holds the information. Path and
filename are obviously strings. Searching has to be on the basis
of both. Other information is just carried along.

With that structure you can simply use a hashtable. You will need
to design a way to dump the table to a file, so you can recreate it
as needed. But the table will provide rapid searching and access.
I would suggest you look at hashlib.zip, to be found at:

<http://cbfalconer.home.att.net/download/hashlib.zip>

which is purely standard C and licenced under the GPL. I.e. free.
The file include application examples.

CBFalconer

unread,
May 9, 2009, 9:11:44 PM5/9/09
to
Keith Thompson wrote:
>
... snip ...

>
> If you're going to snip quoted text, can you please do us all the
> simple courtesy of marking it somehow? "[snip]" and "[...]" are
> commonly used markers.

If you look, you will see that I always mark snipped areas. I
don't mark snippage after my answer, because my answer is not
dealing with that.

CBFalconer

unread,
May 9, 2009, 9:16:24 PM5/9/09
to
Hans wrote:
>
... snip ...

>
> I also checked the dirent.h file. It happened to be included in the
> Bloodshed Dev-C/C++ compiler so it must be common or standard.

What is standard is what is referenced in the Cstandard (C99
below). Also the dinkumware library reference covers the standard
library. Some things are new in C99, i.e. not available in C90.

Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://c-faq.com/> (C-faq)
<http://benpfaff.org/writings/clc/off-topic.html>
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf> (C99)
<http://cbfalconer.home.att.net/download/n869_txt.bz2> (pre-C99)
<http://www.dinkumware.com/c99.aspx> (C-library}
<http://gcc.gnu.org/onlinedocs/> (GNU docs)
<http://clc-wiki.net/wiki/C_community:comp.lang.c:Introduction>
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

Keith Thompson

unread,
May 10, 2009, 12:36:49 AM5/10/09
to
CBFalconer <cbfal...@yahoo.com> writes:
> Keith Thompson wrote:
>>
> ... snip ...
>>
>> If you're going to snip quoted text, can you please do us all the
>> simple courtesy of marking it somehow? "[snip]" and "[...]" are
>> commonly used markers.
>
> If you look, you will see that I always mark snipped areas. I
> don't mark snippage after my answer, because my answer is not
> dealing with that.

Ah, but you snipped the part that explained why your answer made no
sense.

Please mark snippage after your answer. Failing to do so tends to
imply that you've quoted the entire article. Adding a "[...]" isn't
that hard.

Hans

unread,
May 10, 2009, 3:24:39 AM5/10/09
to

You should know from my post that my knowledge of C is very limited.
I'm using my programming knowledge to solve a real-world problem I
have. It has priority. It looks like I'll be doing a lot to solve
"programming problems" with your proposed solution.

Anyway, I was able to write a "working" program to satisfy my specs.
Now, I can focus on other things.

Richard Heathfield

unread,
May 10, 2009, 3:48:15 AM5/10/09
to
Hans said:

> On May 10, 9:09 am, CBFalconer <cbfalco...@yahoo.com> wrote:
>> I would suggest you look at hashlib.zip, to
>> be found at:
>>

<URL elided>


>>
>> which is purely standard C and licenced under the GPL. I.e.
>> free. The file include application examples.
>

> You should know from my post that my knowledge of C is very
> limited.

That's all right. So is Chuck's.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

Richard Heathfield

unread,
May 10, 2009, 3:52:56 AM5/10/09
to
CBFalconer said:

> Keith Thompson wrote:
>>
> ... snip ...
>>
>> If you're going to snip quoted text, can you please do us all the
>> simple courtesy of marking it somehow? "[snip]" and "[...]" are
>> commonly used markers.
>
> If you look, you will see that I always mark snipped areas. I
> don't mark snippage after my answer, because my answer is not
> dealing with that.

Yet you've told other people off for snipping in precisely that way
for precisely that reason.

Okay, so admittedly a telling-off from you is like being savaged by
a cupcake with fondant icing. But it's still hypocrisy.

That's not a huge deal, by the way. Practically everyone is a
hypocrite. Nevertheless, it's best to avoid hypocrisy where
possible, as it can make you look rather silly.

CBFalconer

unread,
May 10, 2009, 5:12:30 AM5/10/09
to
Richard Heathfield wrote:
> CBFalconer said:
>> Keith Thompson wrote:
>>>
>> ... snip ...
>>>
>>> If you're going to snip quoted text, can you please do us all
>>> the simple courtesy of marking it somehow? "[snip]" and "[...]"
>>> are commonly used markers.
>>
>> If you look, you will see that I always mark snipped areas. I
>> don't mark snippage after my answer, because my answer is not
>> dealing with that.
>
> Yet you've told other people off for snipping in precisely that
> way for precisely that reason.

You are either lying or are sorely confused.

Richard

unread,
May 10, 2009, 9:28:12 AM5/10/09
to
CBFalconer <cbfal...@yahoo.com> writes:

> Richard Heathfield wrote:
>> CBFalconer said:
>>> Keith Thompson wrote:
>>>>
>>> ... snip ...
>>>>
>>>> If you're going to snip quoted text, can you please do us all
>>>> the simple courtesy of marking it somehow? "[snip]" and "[...]"
>>>> are commonly used markers.
>>>
>>> If you look, you will see that I always mark snipped areas. I
>>> don't mark snippage after my answer, because my answer is not
>>> dealing with that.
>>
>> Yet you've told other people off for snipping in precisely that
>> way for precisely that reason.
>
> You are either lying or are sorely confused.

[editors note : this should be good.]

--
"Avoid hyperbole at all costs, its the most destructive argument on
the planet" - Mark McIntyre in comp.lang.c

Antoninus Twink

unread,
May 10, 2009, 10:20:07 AM5/10/09
to
On 10 May 2009 at 7:48, Richard Heathfield wrote:

> Hans said:
>> You should know from my post that my knowledge of C is very limited.
>
> That's all right. So is Chuck's.

Miaow!

I think this is working out pretty well. I've noticed that Heathfield
has been noticeably less aggressive towards Jacob recently (still snide,
of course), possibly a bit deflated after the reaction to his
"Rosewater" sock puppet.

It looks like he's found someone else to bully instead - and it couldn't
have happened to a nicer guy!

Richard

unread,
May 10, 2009, 10:47:15 AM5/10/09
to
Antoninus Twink <nos...@nospam.invalid> writes:

Heathfield is an angel compared to that nasty jobsworth Chuck
Falconer. Falconer is an over opinionated incompetent : nothing more,
nothing less.

Kenny McCormack

unread,
May 10, 2009, 11:04:47 AM5/10/09
to
In article <gu6pdo$k1k$6...@news.motzarella.org>,

Richard <rgr...@gmail.com> wrote:
>Antoninus Twink <nos...@nospam.invalid> writes:
>
>> On 10 May 2009 at 7:48, Richard Heathfield wrote:
>>> Hans said:
>>>> You should know from my post that my knowledge of C is very limited.
>>>
>>> That's all right. So is Chuck's.
>>
>> Miaow!
>>
>> I think this is working out pretty well. I've noticed that Heathfield
>> has been noticeably less aggressive towards Jacob recently (still snide,
>> of course), possibly a bit deflated after the reaction to his
>> "Rosewater" sock puppet.
>>
>> It looks like he's found someone else to bully instead - and it couldn't
>> have happened to a nicer guy!
>>
>
>Heathfield is an angel compared to that nasty jobsworth Chuck
>Falconer. Falconer is an over opinionated incompetent : nothing more,
>nothing less.

The death any religion (or, more generally, any non-reality-based
Establishment) is when the people running it start squabbling publicly
amongst themselves. At that point, the common man starts to see the
cracks in the walls, and they lose faith.

This is clearly happening to CLC as we speak.

nick_keigh...@hotmail.com

unread,
May 10, 2009, 11:28:35 AM5/10/09
to
On 9 May, 09:54, Hans <hannibal...@gmail.com> wrote:
> I'm still working on the code placement. This was just to show that
> the ISBN switch worked.
>
> As for the dirent.h, it was from this webpage at the cprogramming.com
> forum:
>
> http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046380353&id...

>
> I also checked the dirent.h file. It happened to be included in the
> Bloodshed Dev-C/C++ compiler so it must be common or standard.

it's a common extension. And since you want to walk directories
and the C standard doesn't provide for this you're going to have
to use such an extension. See if it has some sort of "filter"
option if you want to limit which files you see.


Richard Heathfield

unread,
May 10, 2009, 11:53:17 AM5/10/09
to
CBFalconer said:

> Richard Heathfield wrote:
>> CBFalconer said:
>>> Keith Thompson wrote:
>>>>
>>> ... snip ...
>>>>
>>>> If you're going to snip quoted text, can you please do us all
>>>> the simple courtesy of marking it somehow? "[snip]" and
>>>> "[...]"
>>>> are commonly used markers.
>>>
>>> If you look, you will see that I always mark snipped areas. I
>>> don't mark snippage after my answer, because my answer is not
>>> dealing with that.
>>
>> Yet you've told other people off for snipping in precisely that
>> way for precisely that reason.
>
> You are either lying or are sorely confused.

I'm not lying, and I'm not the one that's confused.

I'm going to give you one example:

<4990CDC9...@yahoo.com>

Since I lack confidence in your ability to track this message down,
let alone understand its significance, I won't bother to look for
more examples. I may, however, point out fresh examples from time
to time as and when they crop up. (And they will, they will.)

Richard

unread,
May 10, 2009, 12:08:58 PM5/10/09
to
nick_keigh...@hotmail.com writes:

What happened to your amit.codebase nym or whatever it was?

Keith Thompson

unread,
May 10, 2009, 1:01:19 PM5/10/09
to
Richard Heathfield <r...@see.sig.invalid> writes:
> CBFalconer said:
>
>> Richard Heathfield wrote:
>>> CBFalconer said:
>>>> Keith Thompson wrote:
>>>>>
>>>> ... snip ...
>>>>>
>>>>> If you're going to snip quoted text, can you please do us all
>>>>> the simple courtesy of marking it somehow? "[snip]" and
>>>>> "[...]"
>>>>> are commonly used markers.
>>>>
>>>> If you look, you will see that I always mark snipped areas. I
>>>> don't mark snippage after my answer, because my answer is not
>>>> dealing with that.
>>>
>>> Yet you've told other people off for snipping in precisely that
>>> way for precisely that reason.
>>
>> You are either lying or are sorely confused.
>
> I'm not lying, and I'm not the one that's confused.
>
> I'm going to give you one example:
>
> <4990CDC9...@yahoo.com>
[...]

Not quite. In that article (which Google Groups makes it inordinately
difficult to find, BTW) Chuck criticized me for snipping a paragraph
from an article of his. I had clearly marked the snippage with
"[...]". My current complaint is that Chuck snipped content without
marking it, which could imply to a reader of Chuck's followup that he
had quoted the entire article.

Richard Heathfield

unread,
May 10, 2009, 1:18:58 PM5/10/09
to
Keith Thompson said:

> Richard Heathfield <r...@see.sig.invalid> writes:

<snip>

>> I'm going to give you one example:
>>
>> <4990CDC9...@yahoo.com>
> [...]
>
> Not quite. In that article (which Google Groups makes it
> inordinately difficult to find, BTW) Chuck criticized me for
> snipping a paragraph
> from an article of his. I had clearly marked the snippage with
> "[...]". My current complaint is that Chuck snipped content
> without marking it, which could imply to a reader of Chuck's
> followup that he had quoted the entire article.

I fully take your point about Google Groups! Finding an example at
all was difficult not because there are so few (which is not the
case) but because Google Groups is such a lousy archive. Rather
than find another one, I'll just wait until the next time it
happens. Shouldn't be long now.

Spiros Bousbouras

unread,
May 10, 2009, 6:05:49 PM5/10/09
to Keith Thompson
On 10 May, 18:01, Keith Thompson <ks...@mib.org> wrote:

> Richard Heathfield <r...@see.sig.invalid> writes:
> > I'm going to give you one example:
>
> > <4990CDC9...@yahoo.com>
>
> [...]
>
> Not quite. In that article (which Google Groups makes it inordinately
> difficult to find, BTW) [...]

How about a link then? And how did you go about finding
it? I wasn't able to.

Ben Bacarisse

unread,
May 10, 2009, 8:28:35 PM5/10/09
to
Spiros Bousbouras <spi...@gmail.com> writes:

The thing in <>s is a message ID. Google Groups can look up a message
by ID (the separate form at the end of the "advanced" search page).

http://groups.google.co.uk/group/comp.lang.c/browse_frm/thread/b370bde2edde6e59/c091811f018de02b?hl=en&q=#c091811f018de02b

I much prefer IDs to be posted since my reader will show me them
directly (if there are still on the server) and the GG solution works
reasonably well for older poists that have gone from my server.

--
Ben.

Keith Thompson

unread,
May 10, 2009, 8:39:22 PM5/10/09
to

Google Groups Advanced Search lets you search for an article by
message-id (you have to drop the '<' and '>'), but it shows you the
entire thread. I then went into Options to show the tree view and
searched it for articles by the same author until I found the right one.

Apparently GG has decided that threads are important and individual
articles are not.

Spiros Bousbouras

unread,
May 10, 2009, 9:41:20 PM5/10/09
to Keith Thompson
On 11 May, 01:39, Keith Thompson <ks...@mib.org> wrote:
> Spiros Bousbouras <spi...@gmail.com> writes:
> > On 10 May, 18:01, Keith Thompson <ks...@mib.org> wrote:
> >> Richard Heathfield <r...@see.sig.invalid> writes:
> >> > I'm going to give you one example:
>
> >> > <4990CDC9...@yahoo.com>
>
> >> [...]
>
> >> Not quite. In that article (which Google Groups makes it inordinately
> >> difficult to find, BTW) [...]
>
> > How about a link then? And how did you go about finding
> > it? I wasn't able to.
>
> Google Groups Advanced Search lets you search for an article by
> message-id (you have to drop the '<' and '>'), but it shows you the
> entire thread.

Well I just tried Groups Advanced Search for the first time and
the link I got (tiny version is http://tinyurl.com/onbz9b) took
me directly to the post.

--
Google Groups are moral Google Groups are good
And clever and modest and misunderstood

nick_keigh...@hotmail.com

unread,
May 11, 2009, 6:05:16 AM5/11/09
to
On 10 May, 17:08, Richard <rgrd...@gmail.com> wrote:

> nick_keighley_nos...@hotmail.com writes:
> > On 9 May, 09:54, Hans <hannibal...@gmail.com> wrote:

> >> I'm still working on the code placement. This was just to show that
> >> the ISBN switch worked.
>
> >> As for the dirent.h, it was from this webpage at the cprogramming.com
> >> forum:
>
> >>http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046380353&id...
>
> >> I also checked the dirent.h file. It happened to be included in the
> >> Bloodshed Dev-C/C++ compiler so it must be common or standard.
>
> > it's a common extension. And since you want to walk directories
> > and the C standard doesn't provide for this you're going to have
> > to use such an extension. See if it has some sort of "filter"
> > option if you want to limit which files you see.
>
> What happened to your amit.codebase nym or whatever it was?

que?

This is the only name I've posted with in years.

Kenny McCormack

unread,
May 11, 2009, 9:36:12 AM5/11/09
to
In article <95ee285d-9df4-4217...@s31g2000vbp.googlegroups.com>,
<nick_keigh...@hotmail.com> wrote:
...

>> What happened to your amit.codebase nym or whatever it was?
>
>que?
>
>This is the only name I've posted with in years.

There was that time, back in '87, I think, where somebody actually
admitted to running a sock puppet.

(For the terminally clueless - i.e., CLC regs - this means: Your denial
is meaningless)

nick_keigh...@hotmail.com

unread,
May 11, 2009, 10:37:56 AM5/11/09
to
On 11 May, 14:36, gaze...@shell.xmission.com (Kenny McCormack) wrote:

> >> What happened to your amit.codebase nym or whatever it was?
>
> >que?
>
> >This is the only name I've posted with in years.
>
> There was that time, back in '87, I think, where somebody actually
> admitted to running a sock puppet.
>
> (For the terminally clueless - i.e., CLC regs - this means: Your denial
> is meaningless)

contrariwise the charge in meaningless
<shrug>

Richard

unread,
May 11, 2009, 1:30:22 PM5/11/09
to
gaz...@shell.xmission.com (Kenny McCormack) writes:

Same writing style with caps missing in all the same places, same
platform and same news reader. I call Keighley out on this one.

Richard

unread,
May 11, 2009, 1:32:32 PM5/11/09
to
nick_keigh...@hotmail.com writes:

Why don't you use a real news server? Your posts would be so more better
formatted.

Try

news.motzarella.org

It's free and if you're not such a dumbarse as Falconer you'll be
up to date with your threads.

CBFalconer

unread,
May 11, 2009, 5:37:29 PM5/11/09
to
nick_keigh...@hotmail.com wrote:
> Richard <rgrd...@gmail.com> wrote:
>
... snip ...

>
>> What happened to your amit.codebase nym or whatever it was?
>
> que? This is the only name I've posted with in years.

That is your penalty for responding to the troll. :-)

Richard Bos

unread,
May 21, 2009, 6:56:26 AM5/21/09
to
Keith Thompson <ks...@mib.org> wrote:

> Spiros Bousbouras <spi...@gmail.com> writes:
> > On 10 May, 18:01, Keith Thompson <ks...@mib.org> wrote:
> >> Richard Heathfield <r...@see.sig.invalid> writes:
> >> > I'm going to give you one example:
> >>
> >> > <4990CDC9...@yahoo.com>
> >>

> >> Not quite. In that article (which Google Groups makes it inordinately
> >> difficult to find, BTW) [...]
> >
> > How about a link then? And how did you go about finding
> > it? I wasn't able to.
>
> Google Groups Advanced Search lets you search for an article by
> message-id (you have to drop the '<' and '>'), but it shows you the
> entire thread. I then went into Options to show the tree view and
> searched it for articles by the same author until I found the right one.

Google Groups Broken Beta is not the only website which lets you search
on a Message-ID. Try, for example, <http://al.howardknight.net/>.

That, BTW, is why a Google Beta link is always worse than a Message-ID.
The latter always remains as valid as it was when posted; the former is
only useable at Google's whim.

Richard

Keith Thompson

unread,
May 21, 2009, 12:27:57 PM5/21/09
to
ral...@xs4all.nl (Richard Bos) writes:
[...]

> Google Groups Broken Beta is not the only website which lets you search
> on a Message-ID. Try, for example, <http://al.howardknight.net/>.

Cool, I'll have to try that.

> That, BTW, is why a Google Beta link is always worse than a Message-ID.
> The latter always remains as valid as it was when posted; the former is
> only useable at Google's whim.

Which is why I've started citing both. URLs, when they work, make it
easier to pull up an article quickly.

0 new messages