Skipping specific characters in files in C

Newbie Member
18Dec2009,14:15   #1
nimsalwayz's Avatar
Hi,
I have been trying unsuccessfully to read in a text file and skip over specific characters - something like what C++ does with cin.ignore().
I need to skip over characters like ';' and '->'.

I hope someone can help me..
Ambitious contributor
18Dec2009,16:16   #2
venami's Avatar
What is the function that you use to read the text file?

Welcome to the forum
Newbie Member
18Dec2009,18:22   #3
nimsalwayz's Avatar
I am using the fscanf function.
An example of a line from the file I am reading from is 1->2;
And I want to read the 1 and 2 , ignoring the '->' and ';'

And thank you so much for the welcome.. I really hope you guys can help
Ambitious contributor
18Dec2009,20:54   #4
venami's Avatar
If you use getc(), then you can check the variable and omit from your manipulation like this:

Code:
#include <stdio.h>

int main()
{
  char c;
  FILE *fp;

  fp = fopen("sample.txt","r");
  while((c = getc(fp)) != EOF)
    {
      if(c == ';' || c == '-' || c == '>')
        continue;
      else
        printf("%c", c);
    }

  fclose(fp);

  return 0;
}
Newbie Member
18Dec2009,22:29   #5
nimsalwayz's Avatar
thank u! You are a lifesaver!
Ambitious contributor
19Dec2009,07:01   #6
venami's Avatar
Welcome.

In case your input file contains the '-' and '>' characters, they will also be omitted from reading along with the '->' symbol. I have given you an idea of how to do the skipping of characters, you should take care of the case that I mentioned here while omitting the characters.