williamsm@armory.dec.com (07/28/87)
Hello out there. This is my first time posting in this area (,although I've watched this area for quite some time ), so please excuse me for any thing that i happen to do wrong. My question concerns the function fscanf() on the vax. How do I use fscanf() in such a way that it bring in the specified number of characters including white space (more importantly ' '), with out terminating the input to each field because of the white space. The example below shows the mothod discused in the book written by Rex Jaeschke, which does not seem to work (7-23). This example work if there is no white space with in the fields. and the [...] suppress is not specified. for(rec=0;(feof(fp)==0);rec++) /* read until end of file */ { fscanf(fp,"%[^/n]10s%[^/n]25s%[^/n]10s%[^/n]4s%[^/n]4s", &Master[rec].unit_sub, &Master[rec].descript, &Master[rec].serial_no, &Master[rec].rev, &Master[rec].qty); { pad(rec); printf("\n[%c] %s %s %s %s %s", /* print contents to screen */ ((char *)(rec+65)), Master[rec].unit_sub, Master[rec].descript, Master[rec].serial_no, Master[rec].rev, Master[rec].qty); } } fclose(fp); return(rec); Thanks in advance. (GONE -------- LIKE THE WIND) MELVIN WILLIAMSMS ARMORY::WILLIAMSM
rlk@chinet.UUCP (Richard Klappal) (07/30/87)
In article <11084@decwrl.DEC.COM> williamsm@armory.dec.com writes: > > My question concerns the function fscanf() on the vax. How do I > use fscanf() in such a way that it bring in the specified number of > characters including white space (more importantly ' '), with out > terminating the input to each field because of the white space. ... > MELVIN WILLIAMSMS > ARMORY::WILLIAMSM Can't guarantee that this will work on the vax, but my berserkelyoid compiler will accept (and the SysV documentation agrees) char string[10+1]; /* 10 chars plus terminating null */ ... fscanf(fp, "%10c", string); ... to read in 10 characters, regardless of whitespace, control codes, etc. -- --- UUCP: ..!ihnp4!chinet!uklpl!rlk || MCIMail: rklappal || Compuserve: 74106,1021 ..!ihnp4!ihu1h!rlk ---
decot@hpisod2.HP.COM (Dave Decot) (08/02/87)
> My question concerns the function fscanf() on the vax. How do I > use fscanf() in such a way that it bring in the specified number of > characters including white space (more importantly ' '), with out > terminating the input to each field because of the white space. Well, you could use fread(buf, 10, 1, fp) to read 10 characters. If you need to scan other stuff before and/or after that in the same call, you could use "%10c" for a format. Dave Decot hpda!decot