Thread: CTRL+Z? How to check it?

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    7

    CTRL+Z? How to check it?

    Some days ago I came here asking about CRC and some things related, well, that part of the project is rady and the CRC is working fine...

    but there was an small line at the end of the project text, saying something like this: if the user doesn´t specifie a file hen calling the CRC we have to use the stdin to read a text that the user will type and will end it with CTRL+Z (^Z in the DOS console), and we have to apply the CRC check to that text...
    It doesn´t seem so hard, but we cannot find how to "identifie" the CTRL+Z within the "stdin"

    and another, smallest problem... when we declare different modules (for example one for working with the input, anotther the output and one last with the CRC check) when we try to use them the compiler "Bloodshed Dev C++" doesn't find them... we have tried different thing bu we cannot find the answer...

    THANKS you!!

    Fran

    PD: i didn't mention it before, but we have to implement in C, (i know this forum is for C, but to evade problems i mention it )

    thanks again

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    ^Z is the DOS EOF character, so either you would just keep reading until EOF, or if that doesn't work look for the 0x1A character in the stream.
    Last edited by zx-1; 09-29-2006 at 08:40 PM.
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by Olimpo
    and another, smallest problem... when we declare different modules (for example one for working with the input, anotther the output and one last with the CRC check) when we try to use them the compiler "Bloodshed Dev C++" doesn't find them... we have tried different thing bu we cannot find the answer...
    Project -> Add Files
    (Don't #include them.)
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > but we cannot find how to "identifie" the CTRL+Z within the "stdin"
    As in
    Code:
    int ch;
    while ( (ch=fgetc(stdin)) != EOF ) {
      // do stuff
    }
    Do not try and compare it with 0x1A or anything like that.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    first of all, sorry for posting it twice... but yesterday hen i post this one the Firefox tell that i wasn't posted because the forum where i was trying to post it was wrong... and we i went backward to retrieve what i had written the firefox had already deleted...
    and today it let me post it, but i dind't know that the other was already here... sorry...

    and thanks for your answres, in a couple of hours comes mi partner of project and we will try all this things (he's got all the code,... )

    thanks
    Last edited by Olimpo; 09-30-2006 at 06:49 AM.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    the EOF isn't working as you say...

    i mean... when the stdind has "hola^Z" it doens´t show me the ^Z but it continue within the while until the stdin only has ^Z, only there it goes out of the while...


  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Normally you type in the ctrl-z as the first character after a newline.

    To do what you want, you may have to do "hola^z^z" to get it to give you an EOF indication in your code.

    But this is a feature of your environment, not something specific to C.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    7
    exactly...

    ther's no way for changing that????

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Maybe - I've never tried (or even needed to).

    Typing stuff in is a replacement for reading a text file, and since text files properly end with a newline, pressing return at the keyboard and then ctrl-z is a natural.

    I see you're using dev-c++, and since you can get the full source code for the whole standard library, you could make it do whatever you wanted it to.
    But you should be wary of changing what everyone else considers to be standard behaviour. It's a lot of trouble to go to to save just one keystroke in one rather exceptional circumstance.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. How can i check a directory for certain files?
    By patrioticpar883 in forum C++ Programming
    Replies: 13
    Last Post: 02-01-2008, 05:27 PM
  3. how to check input is decimal or not?
    By kalamram in forum C Programming
    Replies: 3
    Last Post: 08-31-2007, 07:07 PM
  4. Please check this loop
    By Daesom in forum C++ Programming
    Replies: 13
    Last Post: 11-02-2006, 01:52 AM
  5. how to check for end of line in a text file
    By anooj123 in forum C++ Programming
    Replies: 6
    Last Post: 10-24-2002, 11:21 PM