Thread: argv problems

  1. #16
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by aadil7 View Post
    i am fully behind hard work and writing your own code as getting someone else to do it is pointless
    i am not faulting what you are saying but ive been thinking about this all day and have tried experimenting with code and have tried many different things.
    i have always said this will be my last of all resorts and now it has come down to that!
    Well, if you want me to write it for you... no problem.
    My standard fee is $10,000cdn plus $11 per hour.

  2. #17
    Registered User
    Join Date
    Mar 2010
    Posts
    85
    Quote Originally Posted by claudiu View Post
    Well this will teach you an important lesson then. DON'T LEAVE THINGS UNTIL THE LAST MINUTE. You could have asked these questions the day before or the day before that but you didn't.

    Nobody here is going to do your homework for you. It's unethical, unprofessional and a waste of your time as well as ours. It simply doesn't do anything other than lie to yourself.
    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.

  3. #18
    Registered User
    Join Date
    Mar 2010
    Posts
    85
    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

  4. #19
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547

  5. #20
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by aadil7 View Post
    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.
    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.

  6. #21
    Registered User
    Join Date
    Mar 2010
    Posts
    85
    Quote Originally Posted by claudiu View Post
    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.
    if you do get the thread closed then fair enough! but then if people cant LEARN certain detailed things then i dont really know where the tag your resource for the C and C++ came from on this site.

  7. #22
    Registered User
    Join Date
    Jan 2010
    Location
    Ca, US
    Posts
    29
    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

  8. #23
    Registered User
    Join Date
    Mar 2010
    Posts
    85
    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;
        }

  9. #24
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    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

  10. #25
    Registered User
    Join Date
    Mar 2010
    Posts
    85
    what them to together do is create the file exclusively, only if it deoesnt exist already

  11. #26
    Registered User
    Join Date
    Mar 2010
    Posts
    85
    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

  12. #27
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    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

  13. #28
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    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

  14. #29
    Registered User
    Join Date
    Mar 2010
    Posts
    85
    thanks for that
    i have got that running by removing O_EXCL

    thanks again

  15. #30
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    Closed by request.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual C++ 2010 express problems
    By dnj23 in forum Windows Programming
    Replies: 6
    Last Post: 08-10-2010, 06:16 AM
  2. Most Common problems in C
    By Bayint Naung in forum C Programming
    Replies: 18
    Last Post: 06-02-2010, 08:20 PM
  3. argc, argv
    By Martas in forum C Programming
    Replies: 6
    Last Post: 11-19-2009, 09:39 AM
  4. fread problems or memory problems
    By Lechuza in forum C Programming
    Replies: 1
    Last Post: 03-22-2009, 12:45 PM
  5. more argv and argc
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 09-08-2001, 11:04 PM