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.
- 06-22-2007 #1Just 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.
- 06-22-2007 #2
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:
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.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 '#'*/ }Linux user #126863 - see http://linuxcounter.net/


Reply With Quote
