U
Umesh
Can anyone do it? ARMY1987- what say?
Can anyone do it? ARMY1987- what say?
What? Why am *I* supposed to do that?Umesh said:Can anyone do it? ARMY1987- what say?
This should do it...
int main(void) {
FILE *open;
char word[64]
open = fopen("file.txt", "r");
if(!open) return -1;
while(fscanf(open, "%s", word) != EOF) {
if((strstr(word, "ab") != NULL) || (strstr(word, "cd") !=
NULL)) {
printf("gotcha [%s] !\n", word);
}
}
fclose(open);
}
This should do it...
int main(void) {
FILE *open;
char word[64]
open = fopen("file.txt", "r");
if(!open) return -1;
while(fscanf(open, "%s", word) != EOF) {
if((strstr(word, "ab") != NULL) || (strstr(word, "cd") !=
NULL)) {
printf("gotcha [%s] !\n", word);
}
}
fclose(open);
}
CBFalconer said:This should do it...
int main(void) {
FILE *open;
char word[64]
open = fopen("file.txt", "r");
if(!open) return -1;
while(fscanf(open, "%s", word) != EOF) {
if((strstr(word, "ab") != NULL) || (strstr(word, "cd") !=
NULL)) {
printf("gotcha [%s] !\n", word);
}
}
fclose(open);
}
I suggest you at least try code you suggest, or mark it untested.
Obvious Faults:
return -1 is illegal.
Use EXIT_FAILURE and #include <stdlib>.
The test for fscanf should be "== 1".
Nothing makes cd follow ab.
CBFalconer said:This should do it...
int main(void) {
FILE *open;
char word[64]
open = fopen("file.txt", "r");
if(!open) return -1;
while(fscanf(open, "%s", word) != EOF) {
if((strstr(word, "ab") != NULL) || (strstr(word, "cd") !=
NULL)) {
printf("gotcha [%s] !\n", word);
}
}
fclose(open);
}
I suggest you at least try code you suggest, or mark it untested.
Obvious Faults:
return -1 is illegal. Use EXIT_FAILURE and #include <stdlib>.
The test for fscanf should be "== 1".
Nothing makes cd follow ab.
Failure to return 0 (or EXIT_SUCCESS) at completion.
What else could it be, other than 1 and EOF?CBFalconer said:This should do it...
int main(void) {
FILE *open;
char word[64]
open = fopen("file.txt", "r");
if(!open) return -1;
while(fscanf(open, "%s", word) != EOF) {
if((strstr(word, "ab") != NULL) || (strstr(word, "cd") !=
NULL)) {
printf("gotcha [%s] !\n", word);
}
}
fclose(open);
}
I suggest you at least try code you suggest, or mark it untested.
Obvious Faults:
return -1 is illegal. Use EXIT_FAILURE and #include <stdlib>. s/illegal/implementation-defined
The test for fscanf should be "== 1".
In C99 this is allowed.Nothing makes cd follow ab. So what?
Failure to return 0 (or EXIT_SUCCESS) at completion.
Can anyone do it? ARMY1987- what say?
Trolling square Umesh was jivin' on 29 May 2007 22:00:17 -0700 in
comp.lang.c.
How to extract words containing 'ab' & 'cd' in a text file?'s a bad
trip that Umesh has trolled before! Dig it!
Ladies & gentlemen, please do not respond to trolls. Ignore them and
they will go away.
How to modify the program so that it can extact words starting with
'ab', ending with 'cd' but not containing 'ef'?
How to modify the program so that it can extact words starting with
'ab', ending with 'cd' but not containing 'ef'?
blufox said:Hi Umesh,
How will you write a program which accepts a word from user and prints
some "blah blah" if it starts with "ab".
similiarly how will you write a program which will print "foo bar"
when it finds "cd" as the last two letters in the word.
and on the similar lines how will you write a program which will do
nothing which finds "ef" anywhere in the word?
Combine all the three tests together.
Because, unfortunately he is sitting on the needle.As far as I can tell umesh sees the world as consisting of a blur of
amorphous things: words and strings and lines and they seem to be synonyms
of some sort or other. Until he is willing to sit down and decide on
*definitions* for these three things that have some *invariant* meaning, he
is doomed to wander in the wilderness.
He should finish this table:
word - A word is ...
string - A string is ...
line - A line is ....
He seems to be searching for a needle in a haystack but, unfortunately, he
has no means of identifying what a needle is!
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.