Thread: Text file manipulation problem

  1. #1
    ferretman
    Guest

    Text file manipulation problem

    The following code inserts “~” in a text file. However when it reads and finds a ½, ¼, £ and o (degrees),the program halts.

    Any ideas ?

    #include <stdio.h>

    main()
    {
    /* char buffer [ BUFSIZ ]; */

    char ch;

    while ( (ch = getchar()) >= 0 )
    {
    putchar ( ch );
    if ( ch == 10 )
    puts ( "~" );
    }
    }

  2. #2
    Unregistered
    Guest

    Re: Text file manipulation problem

    Originally posted by ferretman
    puts ( "~" );

    So you want it to write out the chars '~' followed by '\0'?

    Question-ing,
    Joshua Burkholder

  3. #3
    Registered User alex's Avatar
    Join Date
    Sep 2001
    Posts
    132
    Hi!

    The special characters ½, ¼, £ and o(degrees) are extended ASCII characters. i.e., their value is not in the range [0,127].
    The extended ASCII table is in the range [128,255] if you use unsigned char, but they are in the range [-128,-1] if you use unsigned char's. Your compiler is using signed char's by default, so the program stops as soon as a special character is found...

    alex

  4. #4
    ferretman
    Guest

    Compiler

    I am using the CC compiler that ships with HP UX 10 !!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. Input From a Text File - A Specific Problem.
    By Eddie K in forum C Programming
    Replies: 4
    Last Post: 03-09-2006, 03:50 PM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM