i need to print a wildcard * in the output . a program that takes a string as command line argument prints all the files in the directory instead of *. can u help me?

i need to print a wildcard * in the output . a program that takes a string as command line argument prints all the files in the directory instead of *. can u help me?

Post your code, to see what have you done so far.

depends on the operating system -- *nix or MS-Windows? (MAC I don't know about). I believe there are some boost c++ classes that will make your code portable between operating systems.

MS-Windows: FindFirstFile() and FindNextFile() Here is a code snippet that illustrates how to use these functions.

*nix: opendir() and readdir()

can u please post me what is written in the link , i am unable to open it .

can u please post me what is written in the link , i am unable to open it .

The article is probably copyright. But you will get similar articles by googling for "man opendir" which will give you links to the linux man pages for that function.

Here is another example

> i m wrking on linux
Most shells do this for you, the usual question being "how do I turn OFF" wildcard expansion.

If you have
a.txt b.txt and c.txt in your directory, then doing

myprog *.txt

Will invariably result in your program seeing
argv[1] = "a.txt"
argv[2] = "b.txt"
argv[3] = "c.txt"

The article is probably copyright. But you will get similar articles by googling for "man opendir" which will give you links to the linux man pages for that function.

Here is another example

unable to understand it , moreover i dont want to use any quotes while giving a wildcard in command line

> i m wrking on linux
Most shells do this for you, the usual question being "how do I turn OFF" wildcard expansion.

If you have
a.txt b.txt and c.txt in your directory, then doing

myprog *.txt

Will invariably result in your program seeing
argv[1] = "a.txt"
argv[2] = "b.txt"
argv[3] = "c.txt"

i need to print * , and not all the files in the directory. i also dont want to use quotes
is it something related to shell programming

prints all the files in the directory instead of *.

need to print * , and not all the files in the directory.

are you sure you know what you want the program to do? We can not help you if you do not know either.

unable to understand it

I can understand that -- but getting a list of all the files in a directory is not an easy solution. An alternate way of accomplishing that is to open a pipe to the shell's ls command, which will return the files and other info just as if you typed ls on the command line.

are you sure you know what you want the program to do? We can not help you if you do not know either.


I can understand that -- but getting a list of all the files in a directory is not an easy solution. An alternate way of accomplishing that is to open a pipe to the shell's ls command, which will return the files and other info just as if you typed ls on the command line.

its opposite what i need, i wanted to print * and not all files in the directory.
found a solution , there is a tool i need to have to make it work .
thanx for all ur help
any futher knowledge is welcomed:confused:

>>there is a tool i need to have to make it work

please tell us that tool you found??? I'm not at a linux computer right now, but I think all you have to do is use escape character

sh: ./a.out \* <Enter>
This article has been dead for over six months. Start a new discussion instead.