Is it possible to ask the program to read the line after a character?
For example,
1 1 1
2 2 2
3 3 3
*****
4 4 4
5 5 5
I want the program after it detects character '*'. Please advise.
Is it possible to ask the program to read the line after a character?
For example,
1 1 1
2 2 2
3 3 3
*****
4 4 4
5 5 5
I want the program after it detects character '*'. Please advise.
Yes it's totally possible.
Sit down and think about it for a while...
plan out your code
write it up
test it.
If you get stuck post your code here and I'm sure some of us will help...
However; we don't hand out code except in rare cases. You don't learn anything if we just hand you the answers.
Are you referring to something like this?
Well if you logically think about it for a second what do you actually want to do? If I am interpreting right you want to read the lines after the character then you are going to need a loop with a check. Read all the lines and throw them away until you hit the character, make the check true and read the following until EOF or whatever input method you are using.
Last edited by omGeeK; 10-22-2011 at 08:16 PM.
Here's my try...
Code:if(c=='*') { while (c=='*') { continue; if(c=='\n') break; } }
You need to be reading the file in there somplace...
Code:if((c=fgetc(Matrix))=='*') { while (c=='*') { continue; if(c=='\n') break; } }
How about
Or as you were,Code:char buff[BUFSIZ]; while ( fgets( buff, BUFSIZ, Matrix ) != NULL ) { if ( buff[0] == '*' ) { // do something, } else { // do something with 3 numbers in buff } }
Code:while ( (c=fgetc(Matrix)) != EOF ) { if ( c == '*' ) { // do something, } else if ( c == '\n' ) { // do something, } else { // do something, } }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I still don't get it. Is it possible to instant messaging here? Or can someone send me an email at <<snipped>>? I don't want to post my homework script online.
So post something which looks like what you're trying to do.
Say just the "read" and "print" a matrix code, and leave out all the matrix math code you've worked on.
Nobody learns from a 1:1 email/chat session, and there's no way for you to really know whether the person helping you knows what they're talking about.
Open forums are both more responsive (you're not waiting for one person), and self-correcting (any mistake is likely to get pounced on).
Posting your genuine answer is seldom a problem, since you can always prove "I posted it first, therefore you must have copied mine" if it comes down to it.
On the other hand, if you've just found your code on the web and are trying to get us to fix it for you by proxy, then we're likely to find out sooner or later, and that will be the end of it.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Code:do { while ((c=fgetc(Pattern))!='*') { //read 1st pattern [1 1 1;2 2 2;3 3 3] } //compare with Matrix file //Below is the part where I want the prog to read after '*' line so to the next pattern, which I am highly doing it wrongly. if ((c=fgetc(Patterns))=='*') { while((c=fgetc(Patterns))=='*') { continue; } } }while((c=fgetc(Patterns))!=EOF);
Put into words what you want to do. Then break those words down into the simplest steps you can. Then think about how to turn those simple steps into code.
"I want to read lines from a file and when I run into the pattern that is just stars, I want to ... do whatever."
I need to read a line from a file.
I need to compare what I have read to what I want to find.
I need to do something based on what I find.
Keep working at breaking each step down into smaller steps until you can do the final step in words:Now come back when you've done all that.Code:while not at the end of the file read one line and store it if what i read is something do something else do something else
Quzah.
Hope is the first step on the road to disappointment.