pipe output loaded into an array (c)
data coming from a pipe is directory list... ( command "ls" ),
i try to put every filename into an array... Code:
# include <stdio.h> In function `main': color.c:10: warning: assignment makes pointer from integer without a cast color.c:14: warning: assignment makes pointer from integer without a cast |
the signature of strtok is: char * strtok ( const char * string, const char * delimiters );
but when you first call it you call it with string (ls_pipe) being a FILE*, is this your problem? also are you using this without includeing string.h? are you excluding any code in your post? |
this is all the code...
i saw how to use strok here: http://www.cppreference.com/stdstring/strtok.html |
strtok is in the string.h file, i cant compile this because it gives errors saying it doesnt know what strtok is. i dont see how you dont get these errors?! do #include<string.h> and see if anything changes..
again, for the first time when you use strtok you call it as such: (FILE*, char*); but it wants: (const char* string, const char* delimiters); can you upload and send a link this file (color.c)? |
i posted all file code above
after including "string.h" there is this message: color.c:11: warning: passing arg 1 of `strtok' from incompatible pointer type |
its referring to what i said in my previous post, you cant pass ls_pipe/FILE*. they have to be char*'s
|
changed "FILE *ls_pipe;"
to "char *ls_pipe;".. not working... |
whats not working now? same error? different error? if you want help you need to be specific
i dont have access to a linux machine so i cant test this code |
compile message is:
color.c: In function `main': color.c:11: warning: passing arg 1 of `strtok' from incompatible pointer type |
can you make another char* but make it const and set it to the one your passing? pass this new const char* instead.. i dont see why it wouldnt work.
also if you changed your FILE* to char* are you still doing the popen call? are you not getting errors there? |
You need to reread your man pages.
popen gives you a file pointer. But that doesn't contain any actual data that you care about. You have to read from the file, and then pass that data to strtok. |
i try to pass stream from "popen" directly to "strtok"
|
you cant give strtok a (file) stream. if this isnt what you mean post code to go with it as its usually easier to understand
|
check out the example here: http://www.opengroup.org/onlinepubs/...ons/popen.html
Quote:
|
Hi Ygloo,
you may have your reasons for doing this with the popen command - but have you come across the opendir/readdir/closedir commands ? I feel they give you much more control than token seeking does. Cheers, Bruce. |
All times are GMT -5. The time now is 06:14 PM. |