Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Scanning different lines
Index -> Programming, C -> C Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Monstrosity_




PostPosted: Wed Jan 31, 2007 11:50 pm   Post subject: Re: RE:Scanning different lines

md @ Wed Jan 31, 2007 11:03 pm wrote:
Monstrosity_ I am not at all sure what yoru comments mean... but from what I gather you are wrong.

As I'm sure wtd has mentioned before being able to trace code is a key part of programming... so try again and I'll tell you if your closer.

[edit] to clarify contat takes a string and a character and adds teh character to the string. whitespace returns true if hte passed character is a whitespace character. Those seem to be the things that people don't understand...

Ahh, ok. I figured you meant strcat when you put concat. If a function concat were defined like that then yes I see this working fine, aside from the for loop stepping one to far and the mix of buffer/white space checking mentioned in previous post.
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Thu Feb 01, 2007 7:50 am   Post subject: RE:Scanning different lines

Seems I cannot post anything big... but only in this thread.... weird.

Yes, in the original post it does read one too far, however the other thing you mention I am still not seeing.
Monstrosity_




PostPosted: Thu Feb 01, 2007 8:09 am   Post subject: Re: RE:Scanning different lines

md @ Thu Feb 01, 2007 8:50 am wrote:
Yes, in the original post it does read one too far

I was wrong here (3rd brain fart in this thread, I quit), even though you read one to far the null character will be skipped by the white space check.

md @ Thu Feb 01, 2007 8:50 am wrote:
however the other thing you mention I am still not seeing.

What I mean is if your grabbing the whole line, you no longer care about checking the whitespace because you know the whole line will be stored in the same row of the array. This is important if your just reading from the stream so you know when to move to the next row of the array. When you go to use functions like strtol (or atoi, strtod, scanf, fscanf, etc) leading whitespace is skipped, making your white space checks superfluous.
md




PostPosted: Thu Feb 01, 2007 4:57 pm   Post subject: RE:Scanning different lines

see my code reads a line on input (which contains all the numbers) and then get's each individual number on the line and inserts it into the array... methinks maybe you didn't quite get that part?
jamonathin




PostPosted: Sat Feb 03, 2007 11:43 am   Post subject: Re: Scanning different lines

Hey thanks for all the inputs, lol. I pretty well figred it out. It's not so much I didn't know the algorithm, it was that I'm somewhat new to C so I didn't really know many commands of what C could do.

Basically what i did was i took a single character as input. If it was a space, I added 1 to the number in that row, if it was a digit I added that value to my array, then when the user entered "\n", i moved on to the next row.

It worked quite nice and I was able to take in 2+ digit numbers as well (checking if last char entered was a space or digit, then *10 and plus)

I tried your method md, but i kept getting errors cuz I couldn't get the proper syntax and whatnot down. That method too was my first choice, its much easer.

Thanks again for the input guys.
Display posts from previous:   
   Index -> Programming, C -> C Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 2 of 2  [ 20 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: