Space in fscanf crosses any whitespace including newlines, so you could do:
The %s is changed to something that won't stop at the first whitespace, %[^\r\n] will accept all text up to but not including newlines.
...except this is dangerous. There's no way to prevent buffer overruns or do error checking and it will choke at the first mistake in your input. Don't use fscanf. Use fgets and sscanf like I keep telling you.
Last edited by Corona688; 04-08-2015 at 01:03 PM..
Hi,
I have a data file formatted like this:
Ex:
Mike 3434
Jack 481
Peter 12
Alan 926
I want to get this data into 2 variables: "Names" and "Numbers" that I can using one "for" loop to get the value as Names and Numbers
Like this:
for i in 0 1 2 3
do
echo $Names
echo... (12 Replies)
I have 3 columns in an excel sheet.
c1 c2 c3
EIP_ACCOUNT SMALL_TS_01 select A.* from acc;
All the above 3 col shoud be passed a variable in the unix code.
1.How to read an excel file
2.How to pass these data as variable to the unic script (1 Reply)
I am trying to write binary data to a file. My program below:
#include <stdlib.h>
#include <stdio.h>
struct tinner {
int j;
int k;
};
struct touter {
int i;
struct tinner *inner;
};
int main() {
struct touter data;
data.i = 10;
struct tinner... (4 Replies)
Can someone tell me how to do this?
Just a thought that entered my mind when learning about structs.
First thought was:
struct one
{
struct two;
}
struct two
{
three;
}
one->two->three
would this be how you would access "three"? (1 Reply)
Hello,
I have a log file for the year, which contains lines starting with the data in the format of YYYY-MM-DD. I need to get all the lines that contain the DD being 04, how would I do this? I tried using grep "*-*04" but it didn't work.
Any quick one liners I should know about?
Thank you. (2 Replies)
Hi,
I am trying to fetch sysname and nodename using struct utsname. I have two HP-UX servers on with 10 characters and other with 13 characters host name. For the first one I am getting truncated 8 characters as output but for the second one i am getting "Value too large to be stored in data type"... (1 Reply)
Hi,
I have received an application that stores some properties in a file. The existing struct looks like this:
struct TData
{
UINT uSizeIncludingStrings;
// copy of Telnet data struct
UINT uSize;
// basic properties:
TCHAR szHost; //defined in Sshconfig
UINT iPortNr;
TCHAR... (2 Replies)
I have this input.|user1 |10.10.10.10 |23|046|1726 (212) |0
|user2 |10.10.10.11 |23|046|43 (17) |0
|test |10.10.10.12 |23|046|45 (10) |0
|test1 |10.10.10.13 |23|046|89 (32) |0
I need to get the data for a user like thisuser1 1726
user2 43
test 45
test1 89... (11 Replies)
Hi,
I have below data in my flat file.I would like to remove the quotes and comma necessary from the data.Below is the details I would like to have in my output.
Could anybody help me providing the Unix shell script for this.
Input :
ABC,ABC,10/15/2012,"47,936,164.567 ","1,036,997.453... (2 Replies)
We have the data looks like below in a log file.
I want to generat files based on the string between two hash(#) symbol like below
Source:
#ext1#test1.tale2 drop
#ext1#test11.tale21 drop
#ext1#test123.tale21 drop
#ext2#test1.tale21 drop
#ext2#test12.tale21 drop
#ext3#test11.tale21 drop... (5 Replies)
Discussion started by: Sanjeev G
5 Replies
LEARN ABOUT PHP
fscanf
FSCANF(3) 1 FSCANF(3)fscanf - Parses input from a file according to a formatSYNOPSIS
mixed fscanf (resource $handle, string $format, [mixed &$...])
DESCRIPTION
The function fscanf(3) is similar to sscanf(3), but it takes its input from a file associated with $handle and interprets the input
according to the specified $format, which is described in the documentation for sprintf(3).
Any whitespace in the format string matches any whitespace in the input stream. This means that even a tab in the format string can
match a single space character in the input stream.
Each call to fscanf(3) reads one line from the file.
PARAMETERS
o $handle
-A file system pointer resource that is typically created using fopen(3).
o $format
- The specified format as described in the sprintf(3) documentation.
o $...
- The optional assigned values.
RETURN VALUES
If only two parameters were passed to this function, the values parsed will be returned as an array. Otherwise, if optional parameters are
passed, the function will return the number of assigned values. The optional parameters must be passed by reference.
EXAMPLES
Example #1
fscanf(3) Example
<?php
$handle = fopen("users.txt", "r");
while ($userinfo = fscanf($handle, "%s %s %s
")) {
list ($name, $profession, $countrycode) = $userinfo;
//... do something with the values
}
fclose($handle);
?>
Example #2
Contents of users.txt
javier argonaut pe
hiroshi sculptor jp
robert slacker us
luigi florist it
SEE ALSO fread(3), fgets(3), fgetss(3), sscanf(3), printf(3), sprintf(3).
PHP Documentation Group FSCANF(3)