![]() |
| | #1 |
| Registered User Join Date: Oct 2002
Posts: 13
| Code:
char *domainResponse=malloc(1000);
while(fgets(domainResponse, 1000, fp) != NULL)
{
/* String function here to search for 'no match for domain' */
/*fputs(domainResponse, stdout);*/
}
printf("%s\n", domainResponse);
Now, if I remove the comments from line 3 like this: Code:
char *domainResponse=malloc(1000);
while(fgets(domainResponse, 1000, fp) != NULL)
{
/* String function here to search for 'no match for domain' */
fputs(domainResponse, stdout);
}
/*printf("%s\n", domainResponse);*/
I tried a strstr(domainResponse, "No match for domain") - but it always returned NULL, which led me to check what was in domainResponse. Seems if I do the fputs, domainResponse contains text; but if I just try to printf it, domainResponse seems empty. With the fputs operation, domainResponse has a long text paragraph. Please help. Thanks, Tim |
| tetradtech is offline | |
| | #2 |
| Registered User Join Date: Aug 2001
Posts: 202
| did you try it this way?: Code: while(fgets(domainResponse, 1000, fp))
{
.
.
.
}
www.axisoftime.com |
| starX is offline | |
| | #3 |
| Registered User Join Date: Oct 2002
Posts: 13
| After reading your post, yes... After I read your reply, I tried as you suggested. Using the code with the fputs() commented out and the printf() attempting to print domainResponse. Same result. I'll leave as is and you can see - if you'd like. http://www.tetradtech.com/domain_check.htm What you should see on the page after you click on "submit" would be a paragraph responding with whether the domain was available or not. Unfortunately, that doesn't show up. Thanks, Tim |
| tetradtech is offline | |
| | #4 |
| Registered User Join Date: Oct 2002
Posts: 13
| Not a *duh* IMHO Again, I'm new at this. But when you place the results from stdout or stdin into a variable, that variable should contain whatever was read in, yes? Whether domainResponse is in the while() statement or wherever, it should contain the results of the domain search. But I think I'm on to something here, when I moved the fgets() out of the while() and the printf() out of the while(), I only get one line printed out. That's because fgets() reads until it encounters a '\0', correct? So maybe the bw-whois is producing a newline at the end, and that's the last thing in the domainResponse variable. -Tim |
| tetradtech is offline | |
| | #5 |
| Registered User Join Date: Oct 2002
Posts: 13
| Found the problem... That was it...helps to print results to see what's actually happening and to include <br> in your html to see if text is split or one long paragraph. Apparently, the bw-whois prints the output as 4 or 5 separate paragraphs separated by newlines, so the last input into the buffer was a newline. This bit of code fixed the problem and it's FINALLY working. Thanks again for all of your help to this error-prone newbie. Code:
while(fgets(domainResponse, 1000, fp))
{
strcat(temp, domainResponse);
}
printf("<br>\n");
if(strstr(temp, "No match for domain")!=NULL)
{
printf("<b>The domain: %s is available!</b>\n", cgivars[1]);
}
else
{
printf("<b>The domain: %s is unavailable.</b>\n", cgivars[1]);
}
|
| tetradtech is offline | |
| | #6 |
| Registered User Join Date: Oct 2002
Posts: 13
| size of temp Code: char temp = malloc(1000); |
| tetradtech is offline | |
| | #7 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,710
| So why not do strstr on each line as you read it (then set a flag if you find it), rather than risk a buffer overflow with all those strcat's to temp Code: int found = 0;
while( !found && fgets(domainResponse, 1000, fp) ) {
found = strstr( domainResponse, "No match for domain") != NULL ;
}
if ( found ) {
printf("<b>The domain: %s is available!</b>\n", cgivars[1]);
} else {
printf("<b>The domain: %s is unavailable.</b>\n", cgivars[1]);
}
|
| Salem is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| char Handling, probably typical newbie stuff | Neolyth | C Programming | 16 | 06-21-2009 04:05 AM |
| Lame null append cause buffer to crash | cmoo | C Programming | 8 | 12-29-2008 03:27 AM |
| [Inheritance Hierarchy] User Input on program with constructors. How ? | chandreu | C++ Programming | 8 | 04-25-2008 02:45 PM |
| Another overloading "<<" problem | alphaoide | C++ Programming | 18 | 09-30-2003 10:32 AM |
| lvp string... | Magma | C++ Programming | 4 | 02-27-2003 12:03 AM |