|
I've already got some code to read a text file using fscanf() , and now I need it modified so that fields that were previously whitespace-free need to allow whitespace. The text file is basically in the form of:
title: DATA
title: DATA
etc...
which is...
Started by Graphics Noob on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Fgets() use the %[ conversion specifier (with the "exclude option"):
char buf[100]; fscanf(stdin, "%*sI highly suggest you stop using fscanf() and start using fgets() (which reads a whole line to parsing non-exactly-formatted input....
|
|
I'm looking to write a pair of utilities that read in a newline separated list of integers on stdin and output their binary (4 byte) equivalent to stdout, and vice versa.
My first thought was a simple bash/linux command that would do this, but I was unable...
Started by Rich on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
Beware of endianness the stdin....
:)
#include <stdio.h> int main () { int x; while (fscanf(stdin, "%i", &x)) { fwrite(&x, sizeof(x), 1 of fscanf() to read each integer, followed by a fwrite() to write it out should work.
|
|
On Fri, 16 Jan 2009 00:48:57 +0000 (UTC), Vincent Lefevre <vincent+news@vinc17.org
I posted the following message to the Austin Group mailing-list about
(IMHO) a contradiction between POSIX.1-2008 and the ISO C standard.
I haven't had any answer...
Started by Vincent Lefevre on
, 3 posts
by 2 people.
Answer Snippets (Read the full thread at omgili):
But if you write a test program you'll find that
glibc fscanf() returns 1 for an input failure enough data in it for one conversion, so that
fscanf() gets an EAGAIN error when it tries to read.
|
Ask your Facebook Friends
|
Note: I completely reworked the question to more properly reflect what I am setting the bounty for. Please excuse any inconsistencies with already-given answers this might have created. I did not want to create a new question, as previous answers to this...
Started by DevSolar on
, 9 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
Maybe just set the stream's error indicator?
I am", &x); ungetc('9', stdin); scanf("%d", &y); printf("%d, %d\n", x, y);
If the input is "100 of PL22.11 (ANSI "C"), on comp.std.c shed some light....
What fscanf() should do if ungetc() fails.
|
|
Dear all,,
I want to read line-by-line from a given input file,, process each line (i.e. its words) and then move on to other line...
So i am using fscanf(fptr,"%s",words) to read the word and it should stop once it encounters end of line...
but this ...
Started by RBA on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
*/ int n = fscanf(stdin, "%" xstr(MAXLINE) "[^\n = fscanf(stdin, "%" xstr(MAXLINE) "[^\n]%*[^\n]", line); if (!feof(stdin)) { getchar(); } } return 0 is running in line....
Discard the rest upto and including a newline.
|
|
I have to make a user input num/percentage pairs. the code looks like:
while(choice != 0) { printf("enter number"); fgets(line, sizeof(line), stdin);//sizeof(line) is 6 sscanf(line, "%d\n", choice); if(choice > 0) { printf("enter percentage\n"); fgets...
Answer Snippets (Read the full thread at stackoverflow):
Choice != 0) { printf("enter number"); fscanf(stdin, "%d", &choice); if(choice > 0) { printf("enter percentage\n"); fscanf(stdin, "%f", &percentage); //add to an array holding numbers vs percentagesThis isn't necessarily....
|
|
I'd like to scan a variables that form vectors from white space delimited text file and the stumbling block (all to often for me) is lack of elegance.
Currently my scanning code requires delineating the size of the vector as the first element in the file...
Started by Jamie on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Int scan_vector(FILE *fh) { char pad[2]; int i; if (fscanf(fh,"%d %1[:]", &v.Length, &pad) != 2; i++) { if (fscanf(fh, "%lf", &v.value[i]) != 1) return -1; } return 0; }
This attempts to read the vector with scanf_vector(stdin, ....
|
|
I need the MD5 sums of 3 million strings or so in a bash script on ubuntu. 3 million strings -> 3 million MD5 hashes. The trivial implementation takes about 0.005sec per string. That's over 4 hours. What faster alternatives exist? Is there a way to...
Started by Oren Trutner on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Fopen" ); return( 1 ); } while( fscanf(f, "%s", buf) == 1 ) { md5_starts( &ctx ); md5_update( &ctx, buf.
|
|
Saludos a todos. Llevo ya varias semanas intentando encontrar el error pero no doy con el, ya he intentado con muchas cosas pero nada.
Tengo una función que agrega (o al menos, debería agregar) productos a una "base de datos" en .txt, y cual es parte ...
Started by Dtc on
, 3 posts
by 2 people.
Answer Snippets (Read the full thread at forosdelweb):
Precio ) { int i = 0 ; int j = 0 ; rewind ( fp1 ) ; fscanf ( fp1 , "%s" , nuevo_producto_nombre ) ; while ( ! feof ( fp1 ) ) { fscanf ( fp1 , "%s" , nuevo_producto_nombre ) ; i++; } rewind ( fp2 ) ; fscanf ( fp2 , "%f" ,& ( * nuevo....
|
|
How to compare a pointer an integer in C? will not let me do while(pt != '*') in line 76
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#define SIZE 30
#define PEOPLE_SIZE 20
#define PRINT_NETWORK 1
struct people //structure...
Started by alyssa on
, 1 posts
by 1 people.
Answer Snippets (Read the full thread at yahoo):
|