#0 0x00246745 in _IO_getwline_info () from /lib/libc.so.6
#1 0x002468a1 in _IO_getwline () from /lib/libc.so.6
#2 0x002462da in fgetws () from /lib/libc.so.6
#3 0x0804879e in main ()
normally segmentation faults happen often when you create pointers and just assign values to the pointed locations.
if u ever get a segmentation fault, its better to look at your pointers first.
In your code also, i see that you have the pointer "f" and you have just used it without allocating any memory for the pointer. so the pointer may be currently having some garbage value that makes it point to an arbitrary location of the memory.. when you try to access the location pointed by "f" may let u , and sometimes it may give you the error segmentation fault if you were lucky( u are lucky to see these errors otherwise you dont know that you are in trouble, and thats a serious trouble ).
in C you can,
use "malloc()" from the standard library to allocate memory for pointers or even you can just create an array of what ever the size you wish, and point the "f" to the first element of the array.
you must free the space after using with the function "free()".
in C++ you can,
use "new" keyword to allocate memory. i am not very good in C++, so, i will let someone else tell you better about this. ( the new keyword allows you to allocate space from the Heap, and this way is recomended for OOP programming)
you must free the space after using with the function "delete"
I can read the output from the process if I use fgets instead of fgetws. But I am getting special characters in the output for some commands, that is why I wanted to try with fgetws.