[OCLUG-devel] Trouble with strings and files

johnd john at jjdev.com
Wed Jul 7 10:36:10 PDT 2004


James,

just a small pointer...

if you do a 'if x=something'

then you don't really need to do a 'if x!=something'

you could just do an else...

that is pretty much what else is for

I would have done it like:

if ((number % 3) == 0) {                        
	sscanf (number, "%s", &line);           
	fputs (line, div_file);                 
} else {
	sscanf (number, "%s", &line);           
}




On Tue, Jul 06, 2004 at 07:59:16PM -0700, James Colannino wrote:
> Hey everyone.  One of the programming excercises in my C book asked me 
> to write a program that will take numbers from a file, place all the 
> numbers divisible by 3 in one file, and all the numbers not divisible by 
> 3 in another file.  I wrote a program that compiles without any fatal 
> errors (albeit I do get some warnings; I will post if asked), but when I 
> run the program with the correct number of arguments, it seg faults.  I 
> ran strace on it to see what it was failing on, but had trouble locating 
> the exact problem.  Below are URLs pointing to both the C source and 
> strace's output:
> 
> http://james.colannino.org/mailinglist/strace.output
> http://james.colannino.org/mailinglist/twolist.c
> 
> I'm sure there's some blatantly obvious and stupid thing that I'm doing, 
> but for the life of me, I can't figure out what it is.  I'm hoping that 
> someone more experienced can hit me over the head with the correct 
> answer :)  Thanks very much in advance.
> 
> James
> -- 
> My blog: http://www.crazydrclaw.com/
> My homepage: http://james.colannino.org/
> 
> "There are no uninteresting things; only uninterested people." --G.K. 
> Chesterton
> 
> _______________________________________________
> OCLUG-devel mailing list -- OCLUG-devel at oclug.org
> http://mailman.oclug.org/mailman/listinfo/oclug-devel


More information about the OCLUG-devel mailing list