4 Replies - 290 Views - Last Post: 20 April 2013 - 09:54 AM Rate Topic: -----

#1 fledgeling  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 68
  • Joined: 10-October 12

reading specific characters from files

Posted 16 April 2013 - 10:31 AM

Well i want to know if there is a way to read strings from a text using fscanf ( or any other function) ignoring characters that are not letters like commas for example just like fscanf does with spaces...
Thats the first part of my question which unfortunatelly i couldnt write any code about
I have tried to write some code to ignore (in character level with fgetc) these characters i dont want and i used this if statement


z=fgetc(fp);
if ((z!=EOF)&&(65<=z<=90||97<=z<=122))






i runned this thing on debugger and when it was reading for example a ! = 33 it was getting inside the if :( can you please help me ?
thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: reading specific characters from files

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,753
  • Joined: 25-December 09

Re: reading specific characters from files

Posted 16 April 2013 - 11:10 AM

The following isn't doing what you seem to think it is.
if ((z!=EOF)&&(65<=z<=90||97<=z<=122))


In C/C++ you must provide both sides of the equations for example:
(65 <= z && z <= 90)


Of course you could also use the isalnum() function to determine whether the character is an alpha numeric character.

Jim
Was This Post Helpful? 1
  • +
  • -

#3 fledgeling  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 68
  • Joined: 10-October 12

Re: reading specific characters from files

Posted 17 April 2013 - 02:53 AM

View Postjimblumberg, on 16 April 2013 - 11:10 AM, said:

The following isn't doing what you seem to think it is.
if ((z!=EOF)&&(65<=z<=90||97<=z<=122))


In C/C++ you must provide both sides of the equations for example:
(65 <= z && z <= 90)


Of course you could also use the isalnum() function to determine whether the character is an alpha numeric character.

Jim

Thanks a lot Jim your response was really helpful and apreciated :)
Was This Post Helpful? 0
  • +
  • -

#4 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 275
  • View blog
  • Posts: 1,764
  • Joined: 20-September 08

Re: reading specific characters from files

Posted 17 April 2013 - 09:13 PM

You may also like to see this recent link ...

re.getting and splitting a dynamic C string into a list of Dynamic C strings using your choice of delimiters
Was This Post Helpful? 0
  • +
  • -

#5 fledgeling  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 68
  • Joined: 10-October 12

Re: reading specific characters from files

Posted 20 April 2013 - 09:54 AM

thanks for your feedback :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1