Find the answer to your Linux question:
Results 1 to 2 of 2
I am writing multiple client server. I am takink the inputs fron a file which contains no 0f sockets and no of tcp connections. In c programming how do I ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2007
    Posts
    8

    eliminating # from a file


    I am writing multiple client server. I am takink the inputs fron a file which contains no 0f sockets and no of tcp connections. In c programming how do I eliminate string which start from '#'. I used fscanf to read the line.

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,915
    I hope this isn't a homework question.

    Normally if you have a string that may begin with a particular character, you'd do this kind of test in C:

    Code:
    fscanf(filep, "%s", inp_string);
    if (inp_string[0] == '#')
    {
        /*do what you want with lines that dont start with '#'*/
    }
    else
    {
        /*handle all the lines that start with a '#'*/
    }
    There are a couple of gotcha's here - firstly I'm not sure fscanf parameters are in the right order (nobody uses it these days unless they're learning C academically because it's fraught with type problems and buffer issues) and secondly, you need to make sure you're handling strings without overrunning the end of the buffer you've allocated. Oh, and don't forget that there may be \r and \n problems depending on the text file format (Unix or windows) which you may have to deal with.
    Linux user #126863 - see http://linuxcounter.net/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •