c - Writing argv[] through write() -
Here's a bit of a problem. I am trying to write the data that the user has entered in argv [1] I have to use write () to complete it.
int main (int argc, char * argv []) {write (1, "your file's name:", 15); Write (1, argv [1], 100); Return 0; } The above is my code I really want to know what it is to see whether it is possible to function with type 1 which connects the string and variables together.
Even with the above ceremony, I get more when I run the order. For example, if I would have typed in Stakhwarflo is my output screen on argv [1] ...
YourFileName: stackoverflowXDG_VTNR = 7SSH_AGENT_PID = 1733XDG_SESSION_ID = c2CLUTTER_IM_MODULE = ximSESSION = Ubuntu GPG_AGam @ am-GA -880GM-UD2H: ~ $
it should not only display your files: stack overflow
You need to create some code of string.h
For example, strlen
will resolve their issues over printing desired:
write (1, argv [1], Streln (Argv [1]));
Because it is so problem argv [1]
especially 100
bytes were sealed and undefined behavior is.
About using a single write
function to add output, I recommend that strcat
be your code something like this:
#include & lt; String.h & gt; Int main (int argc, char * argv []) {char o [100] = "Your file name:"; Dome (O, AGRV [1]); Write (1, o, strollen (o)); Return 0; }
Hope it helps!
Comments
Post a Comment