Char. troubles !!!!

This is a discussion on Char. troubles !!!! within the C Programming forums, part of the General Programming Boards category; Folks...a very frustrating problem........pls. help. I am reading a input file having special characters like ^L^F^H^I^K^M ...... and so on, ...

  1. #1
    Unregistered
    Guest

    Unhappy Char. troubles !!!!

    Folks...a very frustrating problem........pls. help.

    I am reading a input file having special characters like
    ^L^F^H^I^K^M ...... and so on, among other data.

    I am reading the input file using fread.

    char *buf ;
    Allocate memeory for buf ;
    fread(buf,1,LEN,fp);
    /* I come to know about the value of LEN just before fread
    LEN gives me the number of special characters on current line
    in the input file */

    Point to be noted each '^L','^F'..... are being stored as 'single'
    characters in 'buf'.

    After these characters I go on and read other data from the input
    file and process it.

    In the program I have to convert the special characters to their
    decimal values.Their decimal values are given in the ASCII table.

    I first tired used 'atoi' which obviously didn't work !!!.

    Now I have declared a static multidimensional char. array.
    A sample :

    static char *table[2][33] = {
    {"^@", "^A","^B","^C","^D",..............} ,
    { "1" , "2" ,"3", "4", "5", ................. }
    };


    My problem is I cannot even use 'strcmp' to compare. 'strcmp'
    just fails and dumps core .
    Because spl. chars. read from input file as being read/stored as
    single characters and my array treats each spl. char as strings.

    How do i get the decimal equivalent of such characters in this
    case. I am working on SOLARIS platform.


    Any ideas ....???
    I am really stuck and have no idea how to do it .

    Appreciate all kinds of suggestions.


    Thanks.

  2. #2
    Registered User Engineer's Avatar
    Join Date
    Oct 2001
    Posts
    125

    Exclamation

    I have two things to say:

    1. You are saying that your chars (^M, etc) are stored as single characters. Now in your array you specify those chars as strings, i.e. "^M", as opposed to specifying them as character '^M'.

    2. If you want to compare something and strcmp() is failing you, you can always use memcmp(), which essentially does the same thing, but works on anything that you give it.
    1 rule of the Samurai Code: if you have nothing to say, don't say anything at all!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  2. Conversion Char To Char * Problem
    By ltanusaputra in forum Windows Programming
    Replies: 3
    Last Post: 03-01-2008, 01:06 PM
  3. Replies: 6
    Last Post: 06-30-2005, 08:03 AM
  4. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 04:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21