thanks for your input but just to let you know ive not let nothing till the last minute and this is not no homework!
i take c seriously and want to learn the language, so i guess i am sorry for posting a genuine issue on a forum, even though a forum is where all different people come together to help solve issues and give help.
rather than puts i use printf thats why i am not familiar with it
and the fact that argc is an integer and argv is a string i am not sure how argv[argc] would work
If you really did take this seriously you would have done all your research before coming to ask for help. You have not posted any kind of code that you WROTE since the beginning of the thread, you DON'T ASK QUESTIONS THE SMART WAY, and you generally just keep wasting our time.
People here give help all the time, but only to people who take their work seriously and write THEIR OWN CODE.
I think it's about time this thread was closed.
1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
3. Get rid of conio.h and other antiquated DOS crap headers.
4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.
You asked how do to get the last argument from argv and you were told
argv[argc-1] that's a great answer.
You asked how you access all of argv[] and your were told to loop them, and that is also a good answer.
Do you have a new question? If so just ask it.
But most people also show the code they have tried to let others know you have put some effort into solving your problem.
Dylan
ok then well the part i need to figure out was for the following
Code:outfiled = open(argv[numfiles], O_CREAT | O_WRONLY | O_EXCL , S_IRUSR|S_IWUSR); if (outfiled == -1) { printf("%s\n", argv[numfiles]); printf("%s cannot be opened\n", argv[numfiles]); exit; }
So whats wrong with that code? Is it not opening the file you wanted? I pressume might be cos O_CREAT | O_EXCL.
ssharish
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein
what them to together do is create the file exclusively, only if it deoesnt exist already
when i take O_CREAT and O_EXCL off it works
but for some reason it does not seem to work with them both on
thats right, so what i was thinking was that your open should have been returning -1 if you were opening a file which already exisit. Well if you know what them both does then fair enough. Now tell us what is wrong with the above snap of code whuch you've posted? What is not working?
ssharish
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein
Well basically O_CREAT | O_EXCL flags mean, that the open will check for if the file already exists, if it does then open will fail and return -1. If it doesn't exist open will create a new file. Its a good practice to use the perror function to get reason for why the open fails.
So could you check if file yor tyring to open already excits in the folder? If its does then try deleting it and run your program again?
ssharish
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein
thanks for that
i have got that running by removing O_EXCL
thanks again