Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 525 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to ignore whitespaces in fscanf()

#1
I need to use `fscanf` to ignore all the white spaces and to not keep it.
I tried to use something like the combination between `(*)` and `[^\n]` as: `fscanf(file," %*[^\n]s",);`
Of course it crashed, is there any way to do it only with `fscanf`?

code:

int funct(char* name)
{
FILE* file = OpenFileToRead(name);
int count=0;
while(!feof(file))
{
fscanf(file," %[^\n]s");
count++;
}
fclose(file);
return count;
}


Solved !
change the original `fscanf()` to :
`fscanf(file," %*[^\n]s")`;
read all the line exactly as `fgets()` but didnt keep it!
Reply

#2
Using a space (" ") in the fscanf format causes it to read and discard whitespace on the input until it finds a non-whitespace character, leaving that non-whitespace character on the input as the next character to be read. So you can do things like:

fscanf(file, " "); // skip whitespace
getc(file); // get the non-whitespace character
fscanf(file, " "); // skip whitespace
getc(file); // get the non-whitespace character

or

fscanf(file, " %c %c", &char1, &char2); // read 2 non-whitespace characters, skipping any whitespace before each

from:

[To see links please register here]

Reply

#3
from the fscanf man page:

A directive is one of the following:
· A sequence of white-space characters (space, tab, newline, etc.;
see isspace(3)). This directive matches any amount of white
space, including none, in the input.

so

fscanf(file, " %s\n");


will skip all whitespace before reading in characters.
Reply

#4
Your code is crashing because you have a `%s` in your format specifier in the `fscanf` call, and you don't pass `fscanf` a `char *` to which you want it to write the string it finds.

See

[To see links please register here]

.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through