techies,
i don't where to start to countr two characters in any patterns or from any words like "ei" from "Receive eieiten pooeesiec".
can you give some hints?
techies,
i don't where to start to countr two characters in any patterns or from any words like "ei" from "Receive eieiten pooeesiec".
can you give some hints?
strstr
Don't quote me on that... ...seriously
> strstr
strstr() in a loop.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
i am thinking to use not strstr. suppose, i don't know about str. i just want to use one character at a time. how to remember previous character and current char?
Linked Lists!, with a 'next char node' and/or a 'previous char node'...
Or a loop, with something like;
Code:char * s = "Hello"; while(*s) { // note: you should be checking if p is going to be valid, but thats upto you. // on the first iteration its not going to work... a simple 'if' statement or for() loop would fix this. char p = *s-1, c = *s; // p is prev, c is current char *s++; }
Last edited by zacs7; 03-31-2007 at 05:30 PM.
If the OP doesn't know about strings, I highly doubt they know about pointers.
Perhaps something like this:
Code:char s[] = "Receive eieiten pooeesiec"; size_t x, len = strlen(s); for(x = 1; x < len; x ++) { s[x]; /* char */ s[x-1]; /* previous char */ }
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Yes, well, that's a risk I'll have to take. The more [solutions] the merrier.
If you're just looking for either 'e' or 'i' followed by either an 'e' or an 'i', then I suggest using something like this:
You'll notice I provided links for the functions I used. Say, maybe I should get codeform to do that . . . [edit] http://cboard.cprogramming.com/showp...6&postcount=20 [/edit]Code:char str[] = "Receive eieiten pooeesiec"; char look[] = "ei"; char *p; p = strpbrk(str, look); if(strchr(look, p[1])) { /* found, p[0] and p[1] */ }
Last edited by dwks; 03-31-2007 at 06:24 PM.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Good idea
BUT, what if I haven't studied pointer, array and functions too. I've just finished studying loop and basic of C like getting characters or lines from key board, and counting them.
Isn't there any way with much knowledge?
You've managed to get three people to do your homework for you, or very close to it. Let's see what you actually have done.
Quzah.
Hope is the first step on the road to disappointment.
sorry, u r interpreting wrongly. I am not a computer student nor it's a homework. I am just following book and learning C from that. And, what I am asking is WHAT I don't know, or don't know how to start?
I've done word counting program, vowel counting. But it's out of my reach, i think. I don't know how to do two character comparision at a time. Hope cleared!
Use one variable to track the current character you've just read, and one to hold the one you read right before that. If they're not the same, move this one into the "last time" holder, and read a new one into the "just read" holder. Repeat until done.
Quzah.
Hope is the first step on the road to disappointment.
plz help me. it is stucking in second getchar().
Code:while((ch=getchar())!='#') { ch1 = ch; ch2=getchar(); if(ch1=='a' && ch2=='b') count++; } printf("pattern ab = %d\n",count);
Something like that?Code:while( (ch=getchar()) != '# ) /* read until you find a # */ { if( ch == first_char_to_find ) { int ch2 = getchar( ); if( ch2 == second_char_to_find ) yay++; else ungetc( ch2, stdin ); } }
Quzah.
Hope is the first step on the road to disappointment.