C Program [ Turbo-C ] , to extract only-Printable-characters from a file ( any type of file) and dis

Discussion in 'C Programming' started by SunRise, Jul 2, 2005.

  1. SunRise

    SunRise Guest

    Hi

    I am creating a C Program [ Turbo-C ] , to extract
    only-Printable-characters from a file ( any type of file) and display
    them.
    OS: Windows-XP

    Ple help me to fix the Errors & Warnings and explain how to use
    Command-Line Arguments inside C program.

    thanks
    SunRise

    --------------------------------------------------------
    Warnings & Errors:

    WARNING : Non-portable pointer compariosn in function main
    Error(1) : Illegal structure operation in function main
    Error(2) : Illegal structure operation in function main
    Error(3) : Illegal structure operation in function main
    Error(4) : type mismatch in parameter 'c' in call to "_fputc" in
    function main*/

    --------------------------------------------------------


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


    void main()
    {

    /*char *file1 = argv[1]; */

    FILE *fp1;

    fp1=fopen("c:\\tmp\\tmp\\CPUCount20.exe","r");

    if ( fp1 == NULL ) /* WARNING is here */
    {
    /* printf("Error opening file : %s\n\n", file1); */
    printf("Exiting ...\n");
    exit(1) ;
    }

    while( fp1 != EOF )
    {

    if( isprint(*fp1) ) /* Error(1) & Error(2) */
    {
    putc(*fp1,stdout); /* Error(3) & Error(4) */
    }
    fp1++;
    }


    printf(" ======= End of strings1 ======== \n\n");


    }
     
    SunRise, Jul 2, 2005
    #1
    1. Advertising

  2. SunRise

    CBFalconer Guest

    Re: C Program [ Turbo-C ] , to extract only-Printable-characters from afile ( any type of file) and display them ( i.e equivalent to "strings"command in UNIX)

    SunRise wrote:
    >
    > I am creating a C Program [ Turbo-C ] , to extract
    > only-Printable-characters from a file ( any type of file) and
    > display them.
    > OS: Windows-XP
    >
    > Ple help me to fix the Errors & Warnings and explain how to use
    > Command-Line Arguments inside C program.


    Turbo-C is a 16 bit DOS program, and generally usable on DOS.
    However it doesn't know anything about long file names (anything
    over the 8.3 mark) and WinXP has deliberately crippled the DOS
    operation in order to sell more software :-( However the DJGPP
    system is available for all these problems - see
    <http://www.delorie.com>.

    There, among other things, you will find binutils available. After
    installing that you will find the strings command to be available.
    You can also get the GNU source, together with whatever patches
    were needed to function under DJGPP. gcc comes with it all.

    For examples of source using the command line for parameters, just
    snoop about my download section. See:

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

    --
    "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
     
    CBFalconer, Jul 2, 2005
    #2
    1. Advertising

  3. SunRise wrote on 02/07/05 :
    > #include <stdio.h>
    > #include <ctype.h>
    > #include <process.h>


    Not standard. Use <stdlib.h> for exit()...

    > void main()


    main() returns int. Always.

    > FILE *fp1;
    >
    > fp1=fopen("c:\\tmp\\tmp\\CPUCount20.exe","r");


    If you intend to read a binary file (made of characters 0-255), use
    "rb" instead.

    > while( fp1 != EOF )


    Please read a C-book. The files functions are fgetc(), fgets() etc. And
    don't forget fclose() when finished...

    --
    Emmanuel
    The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
    The C-library: http://www.dinkumware.com/refxc.html

    "Clearly your code does not meet the original spec."
    "You are sentenced to 30 lashes with a wet noodle."
    -- Jerry Coffin in a.l.c.c++
     
    Emmanuel Delahaye, Jul 3, 2005
    #3
  4. SunRise

    Old Wolf Guest

    Re: C Program [ Turbo-C ] , to extract only-Printable-characters from a file ( any type of file) and display them ( i.e equivalent to "strings" command in UNIX)

    Emmanuel Delahaye wrote:
    > SunRise wrote on 02/07/05 :
    >
    >> void main()

    >
    > main() returns int. Always.


    main() may have any number of implementation-defined return types
    and parameter lists, as long as two of them are "int main(void)"
    and "int main(int, char **)".

    In fact the OP's implementation defines "void main(void)" as
    a valid form of main.
     
    Old Wolf, Jul 4, 2005
    #4
  5. Re: C Program [ Turbo-C ] , to extract only-Printable-characters from a file ( any type of file) and display them ( i.e equivalent to "strings" command in UNIX)

    On Sun, 03 Jul 2005 19:27:48 -0700, Old Wolf wrote:

    > Emmanuel Delahaye wrote:
    >> SunRise wrote on 02/07/05 :
    >>
    >>> void main()

    >>
    >> main() returns int. Always.

    >
    > main() may have any number of implementation-defined return types
    > and parameter lists, as long as two of them are "int main(void)"
    > and "int main(int, char **)".


    But anything other than these two, or forms compatible with them are not
    supported by standard C. The "implementation-defined" bit is also a
    C99ism, not that it makes a great deal of difference.

    > In fact the OP's implementation defines "void main(void)" as
    > a valid form of main.


    Does it define it formally as an extension or just use it in code
    examples? But even if it does that doesn't make the construct valid C,
    just valid for that implementation.

    Lawrence
     
    Lawrence Kirby, Jul 4, 2005
    #5
  6. SunRise

    Old Wolf Guest

    Re: C Program [ Turbo-C ] , to extract only-Printable-characters from a file ( any type of file) and display them ( i.e equivalent to "strings" command in UNIX)

    Lawrence Kirby wrote:
    > On Sun, 03 Jul 2005 19:27:48 -0700, Old Wolf wrote:
    > > Emmanuel Delahaye wrote:
    > >> SunRise wrote on 02/07/05 :
    > >>
    > >>> void main()
    > >>
    > >> main() returns int. Always.

    > >
    > > In fact the OP's implementation defines "void main(void)" as
    > > a valid form of main.

    >
    > Does it define it formally as an extension or just use it in code
    > examples? But even if it does that doesn't make the construct valid C,
    > just valid for that implementation.


    Well, does the Standard define how an implementation must
    define its implementation-defined behaviours? :)
    Anyway, I think this qualifies as an exception to "Always",
    as Emmanuel Delahaye wrote.

    > > main() may have any number of implementation-defined return types
    > > and parameter lists, as long as two of them are "int main(void)"
    > > and "int main(int, char **)".

    >
    > The "implementation-defined" bit is also a C99ism


    So C89 did not permit void main() at all?
     
    Old Wolf, Jul 4, 2005
    #6
  7. Re: C Program [ Turbo-C ] , to extract only-Printable-characters from a file ( any type of file) and display them ( i.e equivalent to "strings" command in UNIX)

    On Mon, 04 Jul 2005 15:47:41 -0700, Old Wolf wrote:

    > Lawrence Kirby wrote:
    >> On Sun, 03 Jul 2005 19:27:48 -0700, Old Wolf wrote:
    >> > Emmanuel Delahaye wrote:
    >> >> SunRise wrote on 02/07/05 :
    >> >>
    >> >>> void main()
    >> >>
    >> >> main() returns int. Always.
    >> >
    >> > In fact the OP's implementation defines "void main(void)" as
    >> > a valid form of main.

    >>
    >> Does it define it formally as an extension or just use it in code
    >> examples? But even if it does that doesn't make the construct valid C,
    >> just valid for that implementation.

    >
    > Well, does the Standard define how an implementation must
    > define its implementation-defined behaviours? :)


    C99 says "or in some other implementation-defined manner". The key thing
    about "implementation-defined" is that the implementation must document
    it. So C99 formalises the idea that aform of main() is valid on an
    implementaton not because it "happend to work" but because the the
    implementation documents it as an extension.

    > Anyway, I think this qualifies as an exception to "Always",
    > as Emmanuel Delahaye wrote.


    In the context of standard C, the topic of this newsgroup, "Always" is
    correct. OK I see an argument that the bit from C99 above legitimises
    documented extensions. I don't like this though because the standard
    doesn't constrain the bahaviour of implementation-defined forms, you
    effectively have undefined behaviour under an implementation-defined
    label. This goes against the nature of the term "implementation-defined"
    which usually gives the implementation a restricted choice of possible
    behaviours. The bottom line is that C99 doesn't specify any behaviour for
    void main(void) and in my book that makes void main(void) an invalid
    construct in C99.

    >> > main() may have any number of implementation-defined return types
    >> > and parameter lists, as long as two of them are "int main(void)"
    >> > and "int main(int, char **)".

    >>
    >> The "implementation-defined" bit is also a C99ism

    >
    > So C89 did not permit void main() at all?


    It simply has undefined behaviour in C89. That permits an implementation
    to support it as an extension but it is very clearly not part of the C89
    language.

    Lawrence
     
    Lawrence Kirby, Jul 5, 2005
    #7
  8. SunRise

    S.Tobias Guest

    Re: C Program [ Turbo-C ] , to extract only-Printable-characters from a file ( any type of file) and display them ( i.e equivalent to "strings" command in UNIX)

    Lawrence Kirby <> wrote:
    > On Mon, 04 Jul 2005 15:47:41 -0700, Old Wolf wrote:
    >
    >> Lawrence Kirby wrote:
    >>> On Sun, 03 Jul 2005 19:27:48 -0700, Old Wolf wrote:
    >>> > Emmanuel Delahaye wrote:
    >>> >> SunRise wrote on 02/07/05 :
    >>> >>
    >>> >>> void main()
    >>> >>
    >>> >> main() returns int. Always.
    >>> >
    >>> > In fact the OP's implementation defines "void main(void)" as
    >>> > a valid form of main.
    >>>
    >>> Does it define it formally as an extension or just use it in code
    >>> examples? But even if it does that doesn't make the construct valid C,
    >>> just valid for that implementation.

    >>
    >> Well, does the Standard define how an implementation must
    >> define its implementation-defined behaviours? :)

    >
    > C99 says "or in some other implementation-defined manner". The key thing
    > about "implementation-defined" is that the implementation must document
    > it. So C99 formalises the idea that aform of main() is valid on an
    > implementaton not because it "happend to work" but because the the
    > implementation documents it as an extension.
    >
    >> Anyway, I think this qualifies as an exception to "Always",
    >> as Emmanuel Delahaye wrote.

    >
    > In the context of standard C, the topic of this newsgroup, "Always" is
    > correct. OK I see an argument that the bit from C99 above legitimises
    > documented extensions. I don't like this though because the standard
    > doesn't constrain the bahaviour of implementation-defined forms, you
    > effectively have undefined behaviour under an implementation-defined
    > label. This goes against the nature of the term "implementation-defined"
    > which usually gives the implementation a restricted choice of possible
    > behaviours. The bottom line is that C99 doesn't specify any behaviour for
    > void main(void) and in my book that makes void main(void) an invalid
    > construct in C99.


    I don't understand what is "undefined" about `void main(void)', would
    you please expand on that? ISTM that in defining behaviour the Std
    does not distinguish between different `main' forms, and defines it
    only where applicable; in `void main(void)' case, the termination
    status is (explicitly) unspecified.

    --
    Stan Tobias
    mailx `echo LID | sed s/[[:upper:]]//g`
     
    S.Tobias, Jul 6, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. qazmlp
    Replies:
    2
    Views:
    415
    John Harrison
    Jul 23, 2003
  2. qazmlp
    Replies:
    0
    Views:
    401
    qazmlp
    Jul 23, 2003
  3. Daniel Alexandre
    Replies:
    2
    Views:
    561
    Sibylle Koczian
    Mar 21, 2005
  4. Ron Adam

    dis.dis question

    Ron Adam, Oct 8, 2005, in forum: Python
    Replies:
    5
    Views:
    437
    Ron Adam
    Oct 16, 2005
  5. SunRise
    Replies:
    2
    Views:
    641
    SunRise
    Jul 3, 2005
Loading...

Share This Page