Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!apple!agate!ucbvax!hplabs!hp-pcd!hpcvca!charles From: charles@hpcvca.CV.HP.COM (Charles Brown) Newsgroups: comp.sys.amiga Subject: Re: C scanf question Message-ID: <5660047@hpcvca.CV.HP.COM> Date: 19 Jul 89 21:45:20 GMT References: <19915@louie.udel.EDU> Organization: Hewlett-Packard Co., Corvallis, Oregon Lines: 21 > I'm trying to read it back into the same variables one line at a time. > I've tried > fscanf(file, "%c%c%s\n", &flag1, &flag2, line); > fscanf(file, "%c%c%s ", ...); > fscanf(file, " %c%c%s", ...); > fscanf(file, "\n%c%c%s", ...); > I'm well versed in C but usually have avoided the STDIO routines for > various reasons in the past. Can anyone tell me what I'm doing wrong? > -- Darren I can't say what is specifically wrong here, but I can tell you a better way to do this: Use fgets() to read the line and then use sscanf() to read the line read by fgets(). The scanf() family is ill suited to parsing lines. -- Charles Brown charles@cv.hp.com or charles%hpcvca@hplabs.hp.com or hplabs!hpcvca!charles or "Hey you!" Not representing my employer. "The guy sure looks like plant food to me." Little Shop of Horrors