Hello, I got a program with a fscanf like this:
fscanf(stdin, "%d %d,....
I got many fscanf and files that I'd like to test, the files are like this
10485770 15 51200000
-2 10
10 10485760 10485760
10 10485760 10485760
10 10485760 10485760
Well my question is how can I tell to the program or the compiler to take the inputs not from ...
Hi,
sorry, perhaps this is a stupid question.
I have a file like this:
36 146 10 53 240 133 104 28 51 81 124 ...
so I want to read the numbers from a program, so I do:
.... some function .....
int i;
unsigned char key[16];
FILE *fp;
printf ("\n ------ \n");
// open filename
fp = fopen("key.txt","a");
printf("...
Hi gurus,
How to know that fscanf reached a new line \n in a file.
I have been using my own functions for doing that. I know I can use fgets and then sscanf for my required pattern. But my requirements are not stable, some times I want to get TAB separated strings, some times new line separated strings and some times some special charac...
I am using C. I am having issues with using pointers for the fscanf function. When I try to do:
int *x;
/* ... */
fscanf(file, "%d", x[i]);
My compiler gives me a warning saying "format argument is not a pointer" and the code just doesn't run (I get a message saying "Water.exe has stopped working"). If I replace x with *x, it just doe...
Hello all.
I am currently attempting to read in Hex values from a text file.
There can be multiple lines of Hex's and each line can be as long as needed:
f53d6d0568c7c7ce
1307a7a1c84058
b41af04b24f3eb83ce
Currently, I put together a simple loop to read in the Hex values into an unsigned char line[500] with fscanf as such:
...
I wrote a short bit of code to simply skip num_lines lines in an input file (printing the lines out for debugging purposes. Here's two things I tried that didn't work:
for i = 0 to num_lines do
print_endline (fscanf infile "%s" (fun p -> p));
done;;
for i = 0 to num_lines do
print_endline (fscanf infile "%S\n" (fun p -> p));
done;...
We were given an assignment that involved taking information from a file and storing the data in an array. The data in the file is sorted as follows
New York 40 43 N 74 01 W
the first 20 characters are the name of the city followed by the latitude and longitude. latitude and longitude should be easy with a few
fscanf(i...
Hi,
I need to read in a formatted file that looks something like this.
Code: HARK
Name: Oscar
MRTE: Train
etc
At the moment my code looks like this.
FILE *file;
char unneeded[10];
char whitespace[2];
char actual[10];
file = fopen("scannertest.txt","r");
fscanf(file,"%s",unneeded); // this is the identifier and the colon (code:)
fs...
Hi,
I'm reading in a .txt file. I'm using fscanf to get the data as it is formatted.
The line I'm having problems with is this:
result = fscanf(fp, "%s", ap->name);
This is fine until I have a name with a whitespace eg: St Ives
So I use this to read in the white space:
result = fscanf(fp, "%[^\n]s", ap->name);
However, when I try ...
Hi,
this is my c code that reads a list of URLs from a file , and tries to separate the various parts of the URL.. This is just rough parsing , i'm not bothered about special cases.. I guess there is some fault with the sscanf() statement , when i run this , i get " segmentation FAULT" .. and moreover , the full url is being assigned t...
I've been tasked with updating a function which currently reads in a configuration file from disk and populates a structure:
static int LoadFromFile(FILE *Stream, ConfigStructure *cs)
{
int tempInt;
...
if ( fscanf( Stream, "Version: %d\n",&tempInt) != 1 )
{
printf("Unable to read version number\n");
return 0;
}
c...
Hi,
I got the following code:
char buffer[2047];
int charsRead;
do {
if(fscanf(file, "%2047[^\n]%n%*c", buffer, &charsRead) == 1) {
// Do something
}
} while (charsRead == 2047);
I wanted to convert this code to use dynamically allocated variables so that when calling this code often I won't get heavy memory leakage....
What is the best option if I want to "upgrade" old C-code to newer C++ when reading a file with a semicolon delimiter:
/* reading in from file C-like: */
fscanf(tFile, "%d", &mypost.nr); /*delimiter ; */
fscanf(tFile, " ;%[^;];", mypost.aftername);/* delimiter ; */
fscanf(tFile, " %[^;]", mypost.forename); /*delimiter ; */
fscanf(tFil...
Hello,
I have a list of numbers which looks like this: 1.234D+1 or 1.234D-02. I want to read the file using C. The function atof will merely ignore the D and translate only the mantissa.
The function fscanf will not accept the format '%10.6e' because it expects an E instead of a D in the exponent.
When I ran into this problem in Pytho...
Imagine I have a csv with and each value is an integer. so the first value is the INTEGER 100.
I want fscanf() to read this line, and either tell me it's an integer ONLY, or not. So, it would pass 100 but fail on 100t. What i've been trying to get work is "%d," where the comma is the delimiter of my CSV. so the whole function is
fscan...
I'm trying to read a return delimited file. full of phrases.
I'm trying to put each phrase into a string.
The problem is that when I try to read the file with
fscanf(file,"%50s\n",string);
the string only contains one word. when it bumps with a space it stops reading the string
...
while( fscanf( tracefile, "%s ", opcode ) != EOF ){blah}
Occasionally I need to cause fscanf to re-read a line upon a certain condition in my code being met. Is this possible; how would I do that?
Thanks.
...
I've got some code executing in a while(fscanf != EOF) loop.
However, even when fscanf has finished executing, I need to keep running that code until some conditions are met.
I mean I guess I could copy/paste the code to outside the while(fscanf) loop, and only use global variables, but that seems messy. Surely someone has encountered so...
Hi all
I have a problem with a C application; i have on a .txt file some float numbers and I have to read them and sort in descending way. When i do the fscanf command and then the printf, i get on the screen strange numbers (memory location I suppose). How can i solve the problem?
Thanks in advance
Edited
The application is composed by...
I've got some analysis code (myprog) that sucks in data using the following:
if(5 == fscanf(in, "%s%lf%f%f%f", tag, & sec, & tgt, & s1, & s2))
which works just fine. But in the situation where I've got data files that are separated by commas, I'm currently doing something like:
sed 's/,/ /g' data | myprog
Can I modify the format...