Problem on acquiring arguments with asterisk '*' (C language)


 
Thread Tools Search this Thread
Top Forums Programming Problem on acquiring arguments with asterisk '*' (C language)
# 1  
Old 08-24-2011
Problem on acquiring arguments with asterisk '*' (C language)

Hi everybody, I wrote a simple C programm on Unix (HP-UX). Initially, it has to acquire some arguments by command line and
print them on video. I use:

printf("%s\n",argv[i]);

where 'i' represents the numner of arguments in a 'for' cycle.

Problems begin when I pass a parameter containing '*' character, like this:

ab*1234*

the programm return me this sentence: "No match."

After acquiring, these arguments would be passed to a system call so i need to load these as i write them (with asterisks).

Someone can help me ?

thanks a lot.
Alex.
# 2  
Old 08-24-2011
If you're feeding *something* into your C program as a raw argument without any shell expansion, that's not going to work, it's the shell's job to expand asterisks for you. (Though if you put them in the system() command, they will expand there because system() runs the commands you give it in a shell.) If you're doing that in the shell, I don't know why it's not expanding, and certainly can't tell without seeing your programs (shell and C).

Last edited by Corona688; 08-24-2011 at 10:42 AM..
# 3  
Old 08-24-2011
Quote:
Originally Posted by D4vid
Hi everybody, I wrote a simple C programm on Unix (HP-UX). Initially, it has to acquire some arguments by command line and
print them on video. I use:

printf("%s\n",argv[i]);

where 'i' represents the numner of arguments in a 'for' cycle.

Problems begin when I pass a parameter containing '*' character, like this:

ab*1234*

the programm return me this sentence: "No match."
That just means that there are no files in the current directory that match that criteria...otherwise the shell would have expanded the * before passing it to your program...and if you need to pass the arguments as is then you need to put them in quotes to prevent the shell from expanding them. The error mesage is certainly weird...thogh i think it is one that you put in yourself...but then again it is hard to say without looking at your program.
Quote:
Originally Posted by D4vid
After acquiring, these arguments would be passed to a system call so i need to load these as i write them (with asterisks).

Someone can help me ?

thanks a lot.
Alex.
What system call are we talking about...just to make sure im not confusing it with the system lib call that issues a shell command.
# 4  
Old 08-25-2011
Thanks so much.i understand.i have to manage * by shell script and so i can pass the arguments to C programm.
As you said,I think it's the best way.
I'll try.
Thank you for your full explanation.
Alex
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Proxy Server

Building up apache httpd on AIX - acquiring RPMs etc.

pardon the ed URL refs but I'm not allowed to post URLs yet. and the misspelling in the original thread title, which I can't edit even in 'advanced' greetings all, posting this here rather than in Web Development since I suspect this is rather AIX-specific and will need some arcane knowledge,... (2 Replies)
Discussion started by: maraixadm
2 Replies

2. Programming

How to pass the command line arguments to the shell script in c language?

hi, I am new in the shell script, and c programming with linux. I am looking to pass the arguments in c program that should be executed by the shell script. e.g. #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv) { int i; for (i=1;i<argc; i++) { ... (2 Replies)
Discussion started by: sharlin
2 Replies

3. Shell Programming and Scripting

problem in replacing asterisk in sed

Hi all, Sed is the one which always trobules me :( here is my input : *** it industry need to be evolved *** in the world and hope so *** to be dream the output i am expecting is : *** it industry need to be evolved *** in the world and hope so *** to be dream ... (4 Replies)
Discussion started by: panyam
4 Replies
Login or Register to Ask a Question