Initializing problem

This is a discussion on Initializing problem within the C Programming forums, part of the General Programming Boards category; Hi, Can you explain to me why I can't initialize in this way: Code: c_function(char* arr); int main(int argc, char* ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    Maybe because you have arr as a parameter of main and passing argv as a parameter of c_function?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    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, 04:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21