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.. :nonod:
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
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; }
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.