Like Tree2Likes
  • 2 Post By Salem

Question involving Array and Char

This is a discussion on Question involving Array and Char within the C Programming forums, part of the General Programming Boards category; My Goal is to attach whats in a array into one continuous string, i declare a char DataEntry[200]; Code: strcpy(DataEntry,program_id[0]); ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    32

    Question Question involving Array and Char

    My Goal is to attach whats in a array into one continuous string, i declare a char DataEntry[200];

    Code:
    	 strcpy(DataEntry,program_id[0]);
    	 strcat(DataEntry," ");
    	 strcat(DataEntry,program_name[0]);
    	 
         for(k = 0; k <= val2; k++)
    	 {
    	 strcat(DataEntry," ");
    	 strcat(DataEntry,user_id_E[k]);
    	 }
    However i get an error saying Warning 86: argument 2 conflicts, Any ideas to resolve this issue?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    One of the things you're trying to strcat isn't a char array.

    We can't tell from here, you didn't post enough information.
    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
    Join Date
    May 2009
    Posts
    2,544
    Code:
    user_id_E[k]
    Things like above normally are not pointers

    Try
    Code:
    &user_id_E[k]
    Tim S.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    32
    The & sign works great for the first two arrays however within the for loop it crashes with the same error above Warning 86: argument 2 conflicts
    Code:
    strcpy(DataEntry,&program_id[0]);
    	 strcat(DataEntry," ");
    	 strcat(DataEntry,&program_name[0]);
    	 
         for(k = 0; k < val2; k++)
    	 {
    	  strcat(DataEntry," ");
    	  strcat(DataEntry, &user_id_E[k]); 
    	 }

  5. #5
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    You simply haven't given us enough information. We have no idea what the datatypes of any of your variables are. There's probably even an easier way to do what you're trying to do, but again...not enough info.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    Strange, I still can't see any TYPE information for those variables.

    &array[pos] may be correct (from a type point of view), but it seems unlikely to be what you want.

    char array[] = "hello";

    inside your for loop, would see something like this generated.
    helloellolloloo
    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.

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    32
    Sorry here is more of the coding
    Code:
    char program_id_E [30] = {"FUPOPER"};
    char program_name_E [30] = {"$dsmscm.oper*.fup"};
    char user_id_E [31][30]  ={"stuff","stuff.*"};
    char command_E [31][30] = {"load", "copy"};
    int k, x, j, val1, val2, val3;
    
    main()
    {
    
    strcpy(DataEntry,&program_id_E[0]);
    	 strcat(DataEntry," ");
    	 strcat(DataEntry,&program_name_E[0]);
    	 
         for(k = 0; k < val2; k++)
    	 {
    	  strcat(DataEntry," ");
    	  strcat(DataEntry,&user_id_E[k]); 
    	 }
    		 
    }

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,490
    OK, so perhaps
    Code:
    strcpy(DataEntry,program_id_E);  // same as &arr[0], but less complex
    	 strcat(DataEntry," ");
    	 strcat(DataEntry,program_name_E); // ditto
    	 
         for(k = 0; k < val2; k++)
    	 {
    	  strcat(DataEntry," ");
    	  strcat(DataEntry,user_id_E[k]); // same "pointer" value, but a different type (one where it won't complain)
    	 }
    stahta01 and KMAN999 like this.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with an array involving integration?
    By gulfx01 in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2010, 09:48 PM
  2. error involving char type
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 05-18-2007, 05:54 PM
  3. Very stupid question involving pointers
    By 7smurfs in forum C Programming
    Replies: 6
    Last Post: 03-21-2005, 05:15 PM
  4. array involving even numbers
    By dantestwin in forum C++ Programming
    Replies: 13
    Last Post: 07-10-2004, 08:40 AM
  5. Question involving converting array->int
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 01-13-2002, 08:51 AM

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