does the system(char *) change the string?

V

vbhanu

Hi all,

I have a program which does the followin:

I want to download a html file from a site and then parse it to my
needs. So what i do is construct a string which looks like

wget http://the.site.com/folder/file.html

and the i make the call

printf("%s\n",str);
system(str);

the printf part shows the string to be fine but wget is attempting to
download http://the.site.com/folder/file.html which definitely would
not be on the server. Please tell me what is wrong with this and how to
get around. Also is there is a better way to download a file from net
then please mention that also.

Anticipating a reply,

Thank you,
Bhanu
 
V

Villy Kruse

printf("%s\n",str);
system(str);

the printf part shows the string to be fine but wget is attempting to
download http://the.site.com/folder/file.html which definitely would
not be on the server. Please tell me what is wrong with this and how to
get around. Also is there is a better way to download a file from net
then please mention that also.

Bet you got an invisible character in your str string.


Villy
 
V

vbhanu

how can i correct this?? I am really frustrated the whole code is done
except this part. I desprately some help.

Thank you,

Bhanu
 
M

Mike Wahler

how can i correct this?? I am really frustrated the whole code is done
except this part. I desprately some help.

First thing I'd do is check Villy's idea and examine
each character of the string you build. If you find
some garbage in there, then you'll know what needs to
be done (or prevented from being done) to your string,
then we can help you with that.

Paste the following right after your
statement: printf("%s\n",str);

{
const char *p = str;
while(*p)
printf("%d %c\n", *p, *p);
}
puts("Return to continue");
getchar();


Better still, Do you have a debugger? Do you know how
to use it?

-Mike
 
K

Kenneth Brody

Mike Wahler wrote:
[...]
{
const char *p = str;
while(*p)
printf("%d %c\n", *p, *p);
}
[...]

You may want a "p++" somewhere in there. :)

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
I

Irrwahn Grausewitz

Kenneth Brody said:
Mike Wahler wrote:
[...]
{
const char *p = str;
while(*p)
printf("%d %c\n", *p, *p);
}
[...]

You may want a "p++" somewhere in there. :)

.... but not in one of the places p is used already.
<g,d&r> ;P
 
M

Mike Wahler

Irrwahn Grausewitz said:
Kenneth Brody said:
Mike Wahler wrote:
[...]
{
const char *p = str;
while(*p)
printf("%d %c\n", *p, *p);
}
[...]

You may want a "p++" somewhere in there. :)

... but not in one of the places p is used already.
<g,d&r> ;P

{
const char *p = str;
while(*p)
{
printf("%d %c\n", *p, *p);
++p;
}
}

-Mike
 
K

Keith Thompson

how can i correct this?? I am really frustrated the whole code is done
except this part. I desprately some help.

How can you correct what? Don't assume your readers can easily see
the article to which you're repyling. Provide some context.

If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.

Anyway, your problem is that you have a string that you want to have
the value "wget http://the.site.com/folder/file.html", but it has a
stray non-printable character. Since you haven't told us how you
constructed the string, we have no way of guessing why it's not what
you expect it to be.
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,459
Latest member
Vida00R129

Latest Threads

Top