I am using readline() to get input from a console. I am saving the input strings into a char variable. Then i sprintf the char varible into a buffer by using sprintf(). How can i divide the buffer into a number of arguments?
I am using readline() to get input from a console. I am saving the input strings into a char variable. Then i sprintf the char varible into a buffer by using sprintf(). How can i divide the buffer into a number of arguments?
so for example i typed "Hello World" .. how can I divide the buffer to say ..argv[0] is Hello and argv[1] is World ....or divide it by number of argc
Well, you can use sscanf() to scan words from a string, e.g.
Or use strtok(). This will split up data that you have in some array from readline(). I'm not sure why you're mentioning argv[0] and argv[1] unless it's as an example, because argv[] is already split up into words. Can you give more details?Code:char buffer[BUFSIZ], word1[BUFSIZ], word2[BUFSIZ]; strcpy(buffer, "Hello World"); sscanf(buffer, "%s%s", word1, word2);
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.