|
It looks like you're trying to copy text into a string, but there are quite a few mistakes in the code:
1. A string is an array of characters, for eg. char str[100]. Therefore opt_socket_name[5] is a string that can hold 4 characters (+1 for the null terminator)
3. A * represents a pointer - you can also use a character pointer as a string, but it would point to an existing array of characters.
4. You use either * or an array. In your case, *opt_socket_name[5] means an array of 5 strings.
5. const = constant. Don't use that unless you don't want to modify the string.
So here's what your code should look like:
static char opt_socket_name[20];
main()
{
strcpy(opt_socket_name, "testing");
printf("%s", opt_socket_name);
}
If you're looking for an explanation for your warning and the segmentation fault, here it is: as I mentioned, in your original program, opt_socket_name[i] is a string and *opt_socket_name[i] points to a single character in the string. What you are passing to strcpy is a single character, which in C can be implicitly typecast to an integer, which in turn is typecast to a pointer and hence the warning.
|
|
|
|
|
yeah, That is basically what is I intended to do. I understand with the code you gave me since it is a basic strcpy() syntax. Anyway, thanks for the explanation behind the scene because that is the important thing i want to know. however, im not quite sure about what you mentioned of *opt_socket_name[5] means an array of 5 strings.. So does it means that *opt_socket_name[5] points to 5 strings? What I mean is like this :-
*opt_socket_name[0] is pointing to a string for example char string1[10];
*opt_socket_name[1] is pointing to a string example char string2[10];
*opt_socket_name[2] is pointing to a string for example char string3[10];
*opt_socket_name[i] is pointing to a string for example char stringi[10];
How can i make a program to test this if my understanding here is true. The test is just to secure my knowledge and understanding. Thank a lot.
|
|
|
|
|
You're partially right about the *opt_socket_name[5] thing. You declare the array of pointers using a *, eg. char *opt_socket_name[5].
Now, for a normal pointer, you would assign it the address of an existing variable. Example:
int value = 10;
int *pointer = &value;
printf("%d\n", *pointer);
But the problem is that there is no string data type in C. A string itself is an array of characters and an array is internally a pointer, which means that a string is already a pointer. So the & and * are not used at all. This is how you would use an array of strings:
main() {
int i;
char *opt_socket_name[5];
char string1[10];
char string5[10];
strcpy(string1, "hello 1");
strcpy(string5, "hello 5");
opt_socket_name[0] = string1;
opt_socket_name[4] = string5;
for (i = 0; i < 5; i++)
printf("%s\n", opt_socket_name[i]);
}
|
|
|
|
|
wow. Thanks man. This explanation really helps my understanding in C character pointers. I will try this testing code later. Thanks a lot.
|
|
|
|
|
Any good php editor or IDE for Linux (not vi or emacs)? I would like something like dreamweaver...
Thx!
Ivan
|
|
|
|
|
If you just want a simple editor, try Bluefish[^]. If you want a complete IDE (including debugging etc.) try Eclipse PDT[^].
|
|
|
|
|
|
Not totally sure if they have a linux version but they might.
NetBeans6.5 has built in PHP features
|
|
|
|
|
xHTML Kit is a good editor. I don't remember if I needed to set up for php specifically because it was so long ago but it high lites php as well as javascript, perl (did have to set it up to recognize perl) and HTML or XHTML.
All around it is a great editor.
EditPad Pro is also good but not free.
|
|
|
|
|
I'm studying PHP now, but i want study deeply,i made a wbe sit,www.igolfyoo.com[^]
but i want do it better.and i want add a bookmark on every product.
Anyone can help me!
thanks?
www.igolfyoo.com[^]
|
|
|
|
|
Adding bookmarks is a browser-side function. PHP cannot do this, being a server-side language. However, if you use PHP to dynamically generate Javascript, the Javascript can add bookmarks. Take a look at this script-
http://www.dynamicsitesolutions.com/javascript/add-bookmark-script/[^]
It will show you how to use Javascript to add many bookmarks. The next step is to code your PHP to echo the Javascript to a page.
|
|
|
|
|
Starting simpler might be a better bet, instead of using OsCommerce, try something lighter. Editing oscommerce as a beginner can be troublesome and tricky if you're not completely familiar with the basics of php.
Edit: especially when using a template!!!
|
|
|
|
|
hi all
i would like to know i to attach video files in php using ajax control.
and in some places i use ajax but some time its necesssary to refresh antotehr wise that not show updated data in list.
|
|
|
|
|
|
hi,
i have a page which value is added, edited and deleted using Ajax. in this page when we click on add button than display a textbox and after entering value in this box click on button than value is store in database and show in list box, same process for all but some time its shows value in list box but some time its require refresh or when i enter second data then show last value. this happen some times not all time.
|
|
|
|
|
Well, what do you wanna know ?
If you wanna know how you can solve your problem , I can't solve it without see your snippet code !
Please post your code or refer our to your web page .
|
|
|
|
|
It sounds like you have 2 AJAX queries running. One to send the added text to the database, and then another to refresh the displayed contents. Think of AJAX as XL streams leaving and entering through channels. We need to make sure the XML streams do not attempt to use the same channel. If they do, the second will suffer if the first has not completed yet.
A way to get around this is to assign a random session ID to the XML stream to differentiate it. Consider this Javascript AJAX function-
http://whatsaranjit.com/includes/grabData.js[^]
Notice the line:
url=url+"&sid="+Math.random()
This is so that anytime an AJAX request is initiated, they are unique and will not overlap. Try that out. Good luck!
|
|
|
|
|
Hi, I used to learn Red Hat Linux version 9 and now I didn't continue to study it. At my work place I have a problem with my internet connection that over usage. As I have check with the document, I found that suse linux could be setup as a web proxy (squids) which could control and limit the amount of usage of internet. From here I would like to have a question as follow:
1. Is it possible for me to read only the chapter of setup and configure linux as web proxy?
2. Does the machine run as linux web proxy require one or two network interface card?
3. Do I need to read any additional document regarding to configure and monitoring linux web proxy?
Thank in advance!!!
|
|
|
|
|
For questions 1 and 3: If you're familiar with Linux, yes, it's enough you read up the chapter on squid. I also found a simple tutorial here[^].
For question 2: Generally, you need two. One connects the proxy server to the local network. Another connects it to the internet, unless you're using an interface other than Ethernet.
|
|
|
|
|
I need to create a folder on the server with chinese or japanese name. I encode the folder name to UTF-8. I found that I can create the folder. But name of the folder I created on the server become unreadable code.
Thank for any reply.
|
|
|
|
|
Hi,
I am trying to recieve Mobility Header sent (raw sockets). The problem is after receiving, packets are not sent to ip6_input_finish; it is dropped here. (tshark running shows the packet is received)
int ip6_input(struct sk_buff *skb)
{
//It is coming here and NF_HOOK is returning -1
return NF_HOOK(PF_INET6, NF_INET_LOCAL_IN, skb, skb->dev, NULL,
ip6_input_finish);
}
If you need i will send the sender program.
Thanks,
Chandrashekhar
banshekhar
|
|
|
|
|
Problem got solved after doing ip6tables -F.
Thanks,
Chandrashekhar
banshekhar
|
|
|
|
|
Hi,
Please let me know why the option CONFIG_NETFILTER_DEBUG is set while compiling kernel.
Thanks,
Chandrashekhar
banshekhar
|
|
|
|
|
Hello guys
I'm trying to boot Linux from USB. It's an ISO file. But boot can't continue due to a fatal error. Boot is looking for this livecd.sgn file which I think was included in the image file. Then it had this suggestion of copying the data to hard drive and reboot again. It seems that kernel is expecting this file to be in the hard drive. Really no idea how to proceed with this.
|
|
|
|
|
hello friends,
1.I like to create a dynamic tree view taking data from database. I browsed through net but all the sites have them as controls or their own classes. I like create without components using PHP javascript and ajax.
2.I also like to get values from database when clicking on tree node and place it on a dropdown box without posting it to the server(i,e using ajax).
Thanks in advance,
praveen
modified on Saturday, November 8, 2008 1:52 PM
|
|
|
|