LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Quotation marks and strings - in C (http://www.linuxquestions.org/questions/programming-9/quotation-marks-and-strings-in-c-281952/)

lazyuser 01-25-2005 05:47 AM

Quotation marks and strings - in C
 
Hello,
I writing a program, and I don't know how to insert quotation marks in my code.
For example,
Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
        char url[100] = "http://www.google.com";

        printf("%s", url);
        printf("\n");

        return 0;

}

How would I get url, to store "http://www.google.com", and not http://www.google.com.

Any help would be appreciated.

Lazyuser

Dark_Helmet 01-25-2005 05:50 AM

You have to put in an escape sequence to get a literal double-quote:
Code:

char url[100] = "\"http://www.google.com\"";

lazyuser 01-25-2005 05:59 AM

Thank you for your quick reply, and it worked.
Thanks
Lazyuser

lazyuser 01-25-2005 06:25 AM

Hello, I have a new problem, if anybody can help.
Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
        char url[35] = "\"http://www.google.com\"";


        execl("/usr/bin/wget", "wget", url, 0);


        return 0;

}

When I try to run this program, I get the following error.
--04:21:04-- ftp://%22http//www.google.com%22
=> `www.google.com"'
Resolving %22http... failed: Host not found.
Why is it adding %22 to my code. When I print it, it works. 22 in hex, is the quotation marks, why is it changing them. It compiles fine.
Lazyuser

bigearsbilly 01-25-2005 06:59 AM

sounds like wget is translating the chracters to me.

zaichik 01-25-2005 09:14 AM

You wouldn't need the double quotes in the argument, would you?
Code:

[root@inet root]# wget http://www.google.com
--08:06:48--  http://www.google.com/
          => `index.html'
Resolving www.google.com... done.
Connecting to www.google.com[64.233.167.104]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    [ <=>        ] 2,014          1.92M/s

08:06:48 (1.92 MB/s) - `index.html.1' saved [2014]

[root@inet root]#

Try it without and see if that works.


All times are GMT -5. The time now is 09:29 AM.