Thread: Initializing problem

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    130

    Initializing problem

    Hi,

    Can you explain to me why I can't initialize in this way:

    Code:
    c_function(char* arr);
    
    int main(int argc, char* arr[]){
    :
    :
    c_function(argv[1]);
    :
    :
    }
    What is the correct approach?
    NOTE: this is not a complete code.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    That's a function call.
    Where's the initialisation question?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Quote Originally Posted by Moony View Post
    Hi,

    Can you explain to me why I can't initialize in this way:

    Code:
    c_function(char* arr);
     
    int main(int argc, char* arr[]){
    :
    :
    c_function(argv[1]);
    :
    :
    }
    What is the correct approach?
    NOTE: this is not a complete code.
    Looking at your code what i can see just this

    1. You have a main function which takes the command file arguments
    2. You have a function called c_function which takes string as an argument.
    3. And in the main you send the second command line argument to the function c_function.

    And here is the question to you. What are you trying to initialize. Is it the argv[1]? If not what is it you wanted to do?

    Always try give more information, if you expect something good from others.

    ssharish2005
    Last edited by ssharish2005; 06-10-2007 at 04:46 AM.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Maybe because you have arr as a parameter of main and passing argv as a parameter of c_function?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    that would be more likely an error

    ssharish2005

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. problem with initializing a variable
    By Junktyz in forum C Programming
    Replies: 3
    Last Post: 06-27-2007, 08:46 AM
  3. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  4. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM